type alias KeyOf

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 as ValuesOf.

Examples

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" }

Type Parameters

Definition

T extends unknown[] ? ValueOf<T> : keyof T