UNPKG

506 BTypeScriptView Raw
1/**
2Get keys of the given type as strings.
3
4Number keys are converted to strings.
5
6Use-cases:
7- Get string keys from a type which may have number keys.
8- Makes it possible to index using strings retrieved from template types.
9
10@example
11```
12import type {StringKeyOf} from 'type-fest';
13
14type Foo = {
15 1: number,
16 stringKey: string,
17};
18
19type StringKeysOfFoo = StringKeyOf<Foo>;
20//=> '1' | 'stringKey'
21```
22
23@category Object
24*/
25export type StringKeyOf<BaseType> = `${Extract<keyof BaseType, string | number>}`;