[Typescript] 53. Medium - Shift

Implement the type version of Array.shift

For example

type Result = Shift<[3, 2, 1]> // [2, 1]

 

/* _____________ Your Code Here _____________ */

type Shift<T extends any[], ACC = T> = T extends [infer REMOVED, ...(infer REST)] ? REST: [];


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

type cases = [
  // @ts-expect-error
  Shift<unknown>,
  Expect<Equal<Shift<[]>, []>>,
  Expect<Equal<Shift<[1]>, []>>,
  Expect<Equal<Shift<[3, 2, 1]>, [2, 1]>>,
  Expect<Equal<Shift<['a', 'b', 'c', 'd']>, ['b', 'c', 'd']>>,
]

 

posted @   Zhentiw  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-10-17 [CSS] Tailwindcss: get started
2021-10-17 [CSS] Purgecss to remove unused css
2019-10-17 [TypeScript] Modifier
2019-10-17 [Flutter] Getting Location Data From Across Platforms
2018-10-17 [Javascript] Link to Other Objects through the JavaScript Prototype Chain
2017-10-17 [Redux-Observable && Unit Testing] Use tests to verify updates to the Redux store (rxjs scheduler)
2017-10-17 [Redux-Observable && Unit Testing] Mocking an ajax request when testing epics
点击右上角即可分享
微信分享提示