Skip to content

Instantly share code, notes, and snippets.

@millsp
Created January 17, 2021 19:33
Show Gist options
  • Save millsp/a325510bb43b3e41a728a364b879b3ec to your computer and use it in GitHub Desktop.
Save millsp/a325510bb43b3e41a728a364b879b3ec to your computer and use it in GitHub Desktop.
Create a tuple of N size in TypeScript
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