Created
January 17, 2021 19:33
-
-
Save millsp/a325510bb43b3e41a728a364b879b3ec to your computer and use it in GitHub Desktop.
Create a tuple of N size in TypeScript
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
type Tuple<A, N extends number, T extends unknown[] = []> = { | |
0: Tuple<A, N, [...T, A]> | |
1: T | |
}[ | |
T['length'] extends N | |
? 1 | |
: 0 | |
]; | |
type test0 = Tuple<'coucou', 4>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment