[Typescript] 53. Medium - Shift
typescript Medium 53 shift
2023-09-14 08:59:11 时间
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']>>,
]
相关文章
- typescript 中使用 setTimeout 返回值类型 eslint 检查错误 ‘NodeJS‘ is not defined.eslint(no-undef)
- 巧妙利用TypeScript模块声明帮助你解决声明拓展
- 简单的贪吃蛇小游戏—TypeScript练习
- typeScript学习总结(二)
- TypeScript系列教程《单例》
- 类型体操:探究 TypeScript 内置高级类型
- TypeScript方法装饰器应用
- 让你更好使用 Typescript 的11个技巧
- 推荐一个可无限制阅读medium上付费文章的插件-Medium Unlimited
- 开发者数量2025年预计破亿,TypeScript受欢迎度飙升:GitHub最新年度报告
- TypeScript查漏补缺(基础类型)
- TypeScript遭库开发者嫌弃:类型简直是万恶之源