Created
July 7, 2023 11:52
-
-
Save ScriptRaccoon/32c354ffd8acac173affe94e24116e1e to your computer and use it in GitHub Desktop.
Tuple types in TypeScript with fixed length
This file contains hidden or 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<Length extends number, T, Accumulator extends T[] = []> = | |
Accumulator["length"] extends Length ? | |
Accumulator : | |
Tuple<Length,T,[...Accumulator,T]>; | |
const example: Tuple<3,string> = ["hi","mom","!"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment