typelab / assertions / IsOptionalProperty
type IsOptionalProperty<T, Key> = _IsTrueAndNotNever<IfOptionalProperty<T, Key, true, false>>;Determines whether the type of T[Key] is optional.
| Type Parameter | Description |
|---|---|
|
|
The type to be checked. |
|
|
The key of |
true if T[Key] is optional, false otherwise.
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