Created
November 6, 2021 18:10
-
-
Save Honga1/7898d2c6f9322f7931c39627ed730439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tuple = ["a", "b", "c", "d"] as const; | |
type Tuple = typeof tuple; | |
type FirstElement<Tuple extends readonly any[]> = Tuple[0]; | |
type ShiftOne<Tuple extends readonly any[]> = Tuple extends readonly [Tuple[0], ...infer U] ? U : never; | |
type PopOne<Tuple extends readonly any[]> = Tuple extends readonly [...infer U, Tuple[number]] ? U : never; | |
type LastElement<Tuple extends readonly any[]> = Tuple extends readonly [...Tuple[number], infer U] ? U : never; | |
type Indices<Tuple extends readonly any[], TStart extends number[]> = Tuple['length'] extends 0 ? PopOne<[0, ...TStart]> : Indices<ShiftOne<Tuple>, [Tuple['length'], ...TStart]>; | |
type R = ShiftOne<Tuple>; | |
type LE = LastElement<Tuple>; | |
type I = Indices<Tuple, []> | |
type P = PopOne<Tuple>; |
Author
Honga1
commented
Jan 19, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment