[Typescript] 53. Medium - Shift
typescript Medium 53 shift
2023-09-14 09:00:45 时间
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] Typing Class method with this keyword
- [Typescript] 136. Medium - Object to Union
- [Typescript] 72. Medium - IndexOf
- [Typescript] 68. Medium - Fill
- [Typescript] 66. Medium - IsTuple
- [Typescript Challenges] 28. Medium - Replace
- [Typescript] Index access types
- [TypeScript] instanceof and Type Guards (getPrototypeOf)
- [Typescript] 141. Extreme - Sum
- [Typescript] 136. Medium - Object to Union
- [Typescript] Map an Object to a Union of Tuples
- [Typescript] 98. Medium - Append to object
- [Typescript] 67. Medium - Chunk
- [Typescript] 51. Medium - Mutable
- [Typescript] 34. Medium - String to Union
- [Typescript] 33. Medium - Flatten
- [Typescript] 29. Medium - ReplaceAll
- [Typescript challenge] 20. Medium - Chainable Options
- [TypeScript] Interface
- [Typescript] Create Type From Any Given Data in TypeScript
- [TS] Implement a singly linked list in TypeScript
- SAP UI5 未来发展的趋势之一:拥抱 TypeScript
- 如何全局安装和卸载typescript?typescript常用命令