rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
35 lines (32 loc) • 920 B
TypeScript
import type { List } from ".";
import type { IsFixedLength } from "../Ary/IsFixedLength";
import type { Args, Fn } from "../HKT";
import type { AssertBool } from "../helpers";
/**
* Check if a value is a {@link List} (i.e., fixed-length tuple).
*
* Sig: `(x: unknown) => boolean`
*
* @example
* ```typescript
* type R1 = IsList<readonly [1, 2, 3]>;
* // ^?: true
* type R2 = IsList<[1, 2, 3, 4]>;
* // ^?: true
* type R3 = IsList<readonly []>;
* // ^?: true
* type R4 = IsList<string[]>;
* // ^?: false
* type R5 = IsList<readonly [1, 2, 3, ...number[]]>;
* // ^?: false
* ```
*/
export type IsList<T> = AssertBool<T extends List ? IsFixedLength<T> : false>;
/**
* [Fn] Check if a value is a {@link List} (i.e., fixed-length tuple).
*
* Sig: `(x: unknown) => boolean`
*/
export default interface IsListFn extends Fn<[unknown], boolean> {
def: ([x]: Args<this>) => IsList<typeof x>;
}