Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 700 Bytes

File metadata and controls

43 lines (31 loc) · 700 Bytes

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 Parameters

Type Parameter Description

T

The object type to extract optional keys from.

Returns

The keys of T that are optional.

Example

type Obj = { a: number; b: string | undefined; c?: boolean };
type OptionalKeys = ObjectOptionalKeys<Obj>; // "c"