Skip to content

Init

自 1.0.0 起

获取除最后一个元素外的所有元素。

签名

typescript
type Init<T extends readonly unknown[]> = T extends readonly [...infer I, unknown]
  ? I
  : []

参数

参数描述
T元组类型

示例

基本用法

typescript
import type { Init } from 'uni-types'

type AllButLast = Init<[1, 2, 3]> // [1, 2]
type AllButLastStr = Init<['a', 'b', 'c']> // ['a', 'b']

单元素

typescript
type Single = Init<[string]> // []

空元组

typescript
type Empty = Init<[]> // []

相关

  • Tail - 获取除第一个元素外的所有元素
  • Last - 获取最后一个元素
  • Head - 获取第一个元素

基于 MIT 许可发布