Skip to content
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

Allow spreading arrays after required parameters #15849

Merged
merged 5 commits into from
May 17, 2017

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented May 15, 2017

Fixes #5296 using the simple method described briefly in at the bottom #15747.

Specifically, this treats arrays that are spread as an infinite list of all-optional arguments. This lets you spread arrays into all-optional parameters whose types match.

This simple definition has a few more implications:

  1. You can spread arrays into parameter lists that are too short (and whose body presumably uses arguments) [1].
  2. Length is not checked, even if it is known.
  3. Tuples are not treated specially.

Both of these might come later, but would probably require #6229, @Igorbek's strict-length tuple proposal. And much more code, since this is a one-line change.

[1]

declare function mungeArguments(): string;
declare const stuff: string[];
mungeArguments(...stuff) // ok!

sandersn added 2 commits May 15, 2017 10:17
This allows:

1. Spreading arrays into all-optional parameters whose types match.
2. Spreading arrays into parameter lists that are too short and whose
body presumably uses `arguments`.
@KiaraGrouwstra
Copy link
Contributor

Minor correction: that's #6229 rather than 6629.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants