const arr = [
{ key: 'one', value: '1' },
{ key: 'two', value: '2' },
{ key: 'three', value: '3' },
] as const;
type Keys = GetKeys<typeof arr>;
How to define GetKeys so that Keys would be be 'one' | 'two' | 'three'?
const arr = [
{ key: 'one', value: '1' },
{ key: 'two', value: '2' },
{ key: 'three', value: '3' },
] as const;
type Keys = GetKeys<typeof arr>;
How to define GetKeys so that Keys would be be 'one' | 'two' | 'three'?
You just want to use a lookup type (also called "indexed access type") a few times to get the numeric-keyed elements from the array and then the "key"-keyed properties of those:
type GetKeys<T extends readonly {key: any}[]> = T[number]['key'];
type Keys = GetKeys<typeof arr>;
// type Keys = "one" | "two" | "three"
Hope that helps; good luck!