跳至主要內容

16. Pop

鸭梨小于 1 分钟

16. Pop

<题目描述>

::: playground#ts 16. Pop

@file index.ts

// ============= Test Cases =============
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<Pop<[3, 2, 1]>, [3, 2]>>,
  Expect<Equal<Pop<['a', 'b', 'c', 'd']>, ['a', 'b', 'c']>>,
  Expect<Equal<Pop<[]>, []>>,
]

// ============= Your Code Here =============
type Pop<T> = any

:::

点击查看答案
type Pop<T extends any[]> = T extends [...infer R, any] ? R : []