typelab / conditions / IfTuple
type IfTuple<T, Then, Else> = _IfNotAnyOrNever<T, T extends ReadonlyArray ? number extends T["length"] ? Else : Then : Else, Else>;Resolves to Then if the type T is a tuple (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 a tuple, Else otherwise.
type Yes = IfTuple<[string], 'yes', 'no'>; // 'yes'
type No = IfTuple<string[], 'yes', 'no'>; // 'no'
type YesOrNo = IfTuple<[string] | string[], 'yes', 'no'>; // 'yes' | 'no'