How to dynamically obtain the type of key attribute in an array
const arr = [
{ key: 'a' },
{ key: 'b' },
{ key: 'c' },
];
type key = ??? // key is 'a' or 'b' or 'c'
Type the array as const so the strings don't get widened, and then you can use [number] on the array type to get a union of the objects, and then ['key'] on that to get a union of the strings.
const arr = [
{ key: 'a' },
{ key: 'b' },
{ key: 'c' },
] as const;
type key = typeof arr[number]['key'];