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 / IsRequiredProperty

type IsRequiredProperty<T, Key> = _IsTrueAndNotNever<IfRequiredProperty<T, Key, true, false>>;

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

Type Parameters

Type Parameter Description

T

The type to be checked.

Key

The key of T.

Returns

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

Example

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