Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 877 Bytes

File metadata and controls

58 lines (42 loc) · 877 Bytes

typelab / assertions / IsOptionalProperty

type IsOptionalProperty<T, Key> = _IsTrueAndNotNever<IfOptionalProperty<T, Key, true, false>>;

Determines whether the type of T[Key] is optional.

Type Parameters

Type Parameter Description

T

The type to be checked.

Key

The key of T.

Returns

true if T[Key] is optional, false otherwise.

Example

type Valid = IsOptionalProperty<{ a?: string }, 'a'>; // true
type Invalid = IsOptionalProperty<{ a: string }, 'a'>; // false
type Never1 = IsOptionalProperty<{ a: string }, 'b'>; // never
type Never2 = IsOptionalProperty<{}, 'b'>; // never
type Never3 = IsOptionalProperty<undefined, 'b'>; // never