Type alias KeyOf<Input>

KeyOf<Input>: Input extends ArrayLike
    ? NeverFallback<Defined<Exclude<Partial<Input>["length"], Input["length"]>>, number>
    : `${Exclude<keyof Input, symbol>}`

Generic key for either object or array.

Remarks

Type to represent the type of the key in an ReadOnlyCollection. It automatically omits symbol keys from objects, and uses number for arrays with dynamic length.

Example

const array = [1, 2, 3] as const;
const object = { "🟢": "🟩" } as const;

const arrayKey: KeyOf<typeof array> = 0;
const objectKey: KeyOf<typeof object> = "🟢";

See

ReadOnlyCollection

Type Parameters