Tuple
type
#50838
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
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][]
.The text was updated successfully, but these errors were encountered: