const MyEnum = { foo: 'bar', another: 'baz' } as const;
const MyList = ['apple', 'banana', 'orange'] as const;
function example(param: KeyOf<typeof MyEnum>): void {
// param would be: "foo" | "another"
}
function example2(param: KeyOf<typeof MyList): void {
// param would be: "apple" | "banana" | "orange"
}
This is a utility type that allows you to get the keys from an object or list.
If
T
is a type of list, then this behaves the same asValuesOf
.