typelab / utils / ObjectOptionalKeys
type ObjectOptionalKeys<T> = T extends T ? IsObjectLiteral<T> extends true ? keyof { [K in keyof T as IsOptionalProperty<T, K> extends true ? K : never]-?: true } : never : never;Get the optional keys from T type.
| Type Parameter | Description |
|---|---|
|
|
The |
The keys of T that are optional.
type Obj = { a: number; b: string | undefined; c?: boolean };
type OptionalKeys = ObjectOptionalKeys<Obj>; // "c"