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

Spread arguments should appropriately spread into optional parameters #4759

Closed
DanielRosenwasser opened this issue Sep 12, 2015 · 5 comments
Closed
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@DanielRosenwasser
Copy link
Member

Adapted from #4755.

Currently the following is fine:

function f(...things: any[]) {
    let [a, ...bs] = things;

    // do things with 'a' and 'bs'
}

function g(xs: any[]) {
    f(...xs);
}

However, it might be the case that you want to be clear about how things will be used when your function gets called, so it should be fine to use an optional parameter for a:

function f(a?: any, ...bs: any[]) {
    // do things with 'a' and 'bs'
}

function g(xs: any[]) {
    f(...xs);
//  ~~~~~~~~
}

Currently, with the invocation of f above you'll get the error message Supplied parameters do not match any signature of call target. even though a is optional.

@bootstraponline
Copy link
Contributor

👍

@mhegazy mhegazy added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Sep 17, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Aug 31, 2017

should be subsumed by a fix to #4130

@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Aug 31, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 31, 2017

on a closer look, this is already fixed.

@mhegazy mhegazy closed this as completed Aug 31, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone Aug 31, 2017
@yordis
Copy link

yordis commented Nov 23, 2017

@mhegazy @DanielRosenwasser using "typescript": "^2.7.0-dev.20171123" I am still having this issue everywhere I use spread operator I have to actually do functioName.call(null, value)

I am confused because most of the tickets said close but this still happening

@bootstraponline
Copy link
Contributor

Yeah, I don''t think this works.

let str = "abc";
let arr = [...str];

Maybe it requires some configuration.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants