Length of Tuple(easy)

76 阅读1分钟

Length of Tuple 获取 tuple 类型的长度。

声明一个泛型

type Length<T> = any;

限制泛型参数 T 为 tuple 类型

type Length<T extends readonly unknown[]> = any;

获取 length 属性

type Length<T extends readonly unknown[]> = T['length'];