typelab / conditions / IfObject
type IfObject<T, Then, Else> = _IfNotAnyOrNever<T, T extends object ? Then : Else, Else>;Resolves to Then if the type T is object, otherwise resolves to Else.
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The type to be checked. |
|
|
‐ |
The type to return if |
|
|
|
The type to return if |
Then if T is object, Else otherwise.
type Yes = IfObject<object, 'yes', 'no'>; // 'yes'
type No = IfObject<string, 'yes', 'no'>; // 'no'
type YesOrNo = IfObject<object | string, 'yes', 'no'>; // 'yes' | 'no'