Default rest parameter names to destructuring names when of an anonymous tuple #56289
Open
5 tasks done
Labels
Experience Enhancement
Noncontroversial enhancements
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
π Search Terms
default rest parameter name destructure anonymous tuple
β Viability Checklist
β Suggestion
Right now, when calling a function with an inline destructured rest parameter whose type is an anonymous tuple, the inferred variable names will be auto-generated like
__0_0
:In cases where the tuple is destructured inline, how about any constant/static destructuring names being used as a fallback for anonymous tuple elements?
I.e.:
π Motivating Example
The pattern of immediately destructured rest parameters of a tuple is one that sometimes gets used for better type safety on parameters than generics or overloads. One downside, though, is that developers have to either explicitly add names to the tuple type or suffer from poor auto-generated parameter hints.
A slightly more real-world example:
With this suggested change, the parameter hints for
logFruitTuple
would instead be:π» Use Cases
This pattern of destructuring rest parameters of a tuple type allows for precise descriptions of type parameters. It can sometimes be preferable for types over:
Thanks to @evangalen for noting this in https://twitter.com/EmilVanGalen/status/1719622053769216013!
The text was updated successfully, but these errors were encountered: