#Generic that generates types from const assertion mapped/filtered into different forms

5 messages · Page 1 of 1 (latest)

warped glenBOT
#
tickleme_pink#0

Preview:ts const data = [ { key: "X", attr: ["A", "B", "C", "D"], state: "Good", }, { key: "Y", attr: ["D", "E", "F"], state: "Bad", }, { key: "Z", attr: ["D", "A", "B"], state: "Bad", }, ] as const type Data = typeof data[number] ...

scarlet edge
#

In this example, I'm remapping by key and filtering by state. No I want to filter by attr containing a specific value and I might remap using something other than Key and filter on a new field I might add in the future.

#

I already have DataBy which allows me to map by anything that is of type string. How do I generalize HasState/hasState/filterData?

scarlet edge
#

This looks like it does it for 1 level: