Closed mstephen19 closed 2 years ago
See https://github.com/microsoft/TypeScript/issues/39522#issuecomment-656201388:
We've opted to not include utility type aliases in the lib unless they're required for declaration emit purposes.
Related: #47874
The
Tuple
typeWe want to create a type called
Strings50
that is a tuple with 50 strings.Welp, that's one way of doing it. Or, you could use this utility type I'm proposing:
With this recursive type, the abomination above can be refactored to this:
Use case example
We have a function that takes in an array and a chunk size, then returns that same array chunked out:
This is fine. The function returns
T[][]
, andx
is astring[][]
. But, since for our use case, we intend to use non-dynamic chunk sizes when calling this function, we can make the return type more accurate:Instead of having the type
string[][]
,x
now has a type of[string, string][]
, andy
of course has a type of[string, string, string][]
.