Is there some way to extract property values from array?
const d = [{id: 'Cat'}, {id: 'Dog'}]
type ids = ??? //insert code here, type should be 'Cat' | 'Dog'
(It would also work if it generates a const enum)
When you declare d with as const, you can extract the information like this:
const d = [{id: 'Cat'}, {id: 'Dog'}] as const
type IDs = typeof d[number]["id"]
as const is needed: literal types won't work otherwise, so you'd only be able to get the less strict string. typescriptlang.org/docs/handbook/2/…as const when importing a json file?as const. So this may be possible in the future.