Skip to content

Allow spreading arrays after required parameters#15849

Merged
sandersn merged 5 commits into
masterfrom
allow-spread-after-required-params
May 17, 2017
Merged

Allow spreading arrays after required parameters#15849
sandersn merged 5 commits into
masterfrom
allow-spread-after-required-params

Conversation

@sandersn
Copy link
Copy Markdown
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
Copy Markdown
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