-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Simplify longer tuple definitions #47874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What if instead of trying shorter cryptic type that starts with 3 strings and ends with 2 numbers (no idea what API can be described this way, instead of an object), it was tuple with labeled elements so any user will know correct order of some strings and some numbers, not only type and count? |
It's weird that the only use case listed for this is the same as the motivating example. Is there some actual real-world situation where tuples like this are being used that are so long as to be hard to use? I'd expect a motivating example to be like Aaanyway, given that #26223 is closed as fixed you can do something like this yourself without too much trouble and without extra syntax: type ArrayWithLengthFive = [...TupLen<3, string>, ...TupLen<2, number>];
// type ArrayWithLengthFive = [string, string, string, number, number]
type LenTwentyFour = [...TupLen<17, string>, ...TupLen<7, number>];
// type LenTwentyFour = [string, string, string, string, string, string, string,
// string, string, string, string, string, string, string,
// string, string, string, number, number, number, number, number, number, number]; π βtype TupLen<N extends number, T = any, A extends T[] = []> =
N extends A['length'] ? A : TupLen<N, T, [T, ...A]>; |
This is terrifying |
This doesn't come up often enough that we would "spend" syntax/complexity on it. |
Suggestion
π Search Terms
Simplify longer tuple definitions.
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
π Motivating Example
type ArrayWithLengthFive = [string, string, string, number, number];
Simplify
type ArrayWithLengthFive = [string * 3, number * 2];
π» Use Cases
type ArrayWithLengthFive = [string, string, string, number, number];
Simplify
type ArrayWithLengthFive = [string * 3, number * 2];
I haven't assessed feasibility, but I'd like to mention it anywayπ.
The text was updated successfully, but these errors were encountered: