-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshift.ts
29 lines (27 loc) · 833 Bytes
/
shift.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { Equal } from '@type-challenges/utils'
import type { UnknownArray } from '../unknown-array'
/**
* Remove the first element from a tuple type. Does not return the removed type.
*
* @remarks Its worth noting `Pop`, `Push`, `Shift`, and `Unshift` are inspired by JS; however, the types are not 1:1 for design reasons. More information can be found in [README](https://github.com/Cuppachino/type-space/#type-space).
* @example
* ```
* declare const tuple: [1, 2, 3]
* type Tuple = Shift<typeof tuple> // [2, 3]
* ```
*/
export type Shift<T extends UnknownArray> = T extends [any, ...infer U]
? U
: T extends readonly [any, ...infer U]
? readonly [...U]
: never
/**
* @internal
*/
type _shift_cases = [
// ^?
Equal<Shift<[1, 2]>, [2]>,
// ^?
Equal<Shift<readonly [1, 2]>, readonly [2]>
// ^?
]