question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

anonymous rest arguments

See original GitHub issue

Since 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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Mouvediacommented, Apr 17, 2016

If there’s no objections I will proceed with the merge.

0reactions
ericelliottcommented, Apr 15, 2016

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 to Any are we looking at a parameter name? (The default assumption). At what point can you discover that Any 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 that Any[] 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 as Any and Predicate 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found