anonymous rest arguments
See original GitHub issueSince parameter names can be omitted (see Anonymous Parameters), how do I type rest arguments anonymously? How about:
Named:
(...args: Any[]) => Array
Anonymous:
(...Any) => Array
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Rest parameters and spread syntax
Rest parameters and spread syntax. Many JavaScript built-in functions support an arbitrary number of arguments. For instance:.
Read more >Feature #18351: Support anonymous rest and keyword rest ...
Anonymous rest and keyword rest arguments were already supported in method parameters, this just allows them to be used as arguments to other...
Read more >JavaScript Anonymous Functions
In this tutorial, you will learn about JavaScript anonymous functions that can be used as arguments for other functions.
Read more >How many arguments does an anonymous function expect in ...
The arity of an anonymous function is determined by the highest argument referenced inside. e.g.. (#(identity [2])) -> arity 0, 0 arguments must ......
Read more >Arrow function expressions - JavaScript - MDN Web Docs
Rest parameters, default parameters, and destructuring within params are ... Let's decompose a traditional anonymous function down to the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If there’s no objections I will proceed with the merge.
From chat:
When I say easy to parse, I’m not just talking about human parsing. I’m also talking about the parser itself.
(...Any[]) => Array
requires more complex lookahead rules than(...: Any[]) => Array
because the former creates ambiguity. When we get toAny
are we looking at a parameter name? (The default assumption). At what point can you discover thatAny
is actually the type annotation? Maybe when you hit the square brackets you can realize you’ve made a parsing mistake… at which point you have to rewind the parser state.In the
(...: Any[]) => Array
example, the parameter name is already optional, and the:
disambiguates and makes it clear thatAny[]
is the type annotation. Which means there is no lookahead required, and there won’t be a need to rewind the parser state.A human being reading the signature might recognize the built-in
Any
type and assume that it’s the type annotation, but we can’t disambiguate that way in the parser, because some type names, such asAny
andPredicate
are perfectly valid parameter names.I normally rate user friendliness over parser friendliness, but in this case, I feel that the
(...: Any[]) => Array
notation is friendlier to users, too, because it’s logically consistent with the rest of the spec rules. In fact, if we change nothing in the existing spec documentation, that is currently legal syntax. If we wanted to make it illegal, we’d actually have to add a rule to the spec to do so.Regardless of all that, I would still recommend that users stick to
(...args: Any[]) => Array
because there’s no ambiguity, the intent is crystal clear, and it’s only a few more keystrokes.