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