typelab / conditions / IfArray
type IfArray<T, Then, Else> = _IfNotAnyOrNever<T, T extends ReadonlyArray ? Then : Else, Else>;Resolves to Then if the type T is an array (readonly or writable), 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 an array, Else otherwise.
type Yes = IfArray<string[], 'yes', 'no'>; // 'yes'
type No = IfArray<string, 'yes', 'no'>; // 'no'
type YesOrNo = IfArray<string[] | string, 'yes', 'no'>; // 'yes' | 'no'