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

rest args are busted #12956

Closed
billti opened this issue Dec 15, 2016 · 2 comments
Closed

rest args are busted #12956

billti opened this issue Dec 15, 2016 · 2 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@billti
Copy link
Member

billti commented Dec 15, 2016

Using the latest master, this seems to be a pretty serious regression. I noticed my site broke, and tracked it down to an object rest regression.

Basically this code:

let arg = {a: true, b: "test", c: 42};

let fn = ({a, ...rest}) => {
    console.log(`a is: ${JSON.stringify(a)}`);
    console.log(`rest is ${JSON.stringify(rest)}`);
}

fn(arg);

Is generating this emit:

var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p))
        t[p] = s[p];
    return t;
};
var arg = { a: true, b: "test", c: 42 };
var fn = function (_a) {
    var a = _a.a, rest = __rest(_a, ["a"]);
    console.log("a is: " + JSON.stringify(a));
    console.log("rest is " + JSON.stringify(rest));
};
fn(arg);

Which produces this output

a is: true
rest is {"a":true}

The issue is with !e.indexOf(p), as this only returns "true" for the property which is the first in the list (i.e. the index is 0). It should probably be e.indexOf(p) < 0.

CC @mhegazy @rbuckton

@billti billti added Bug A bug in TypeScript High Priority labels Dec 15, 2016
@mhegazy mhegazy added this to the TypeScript 2.1.5 milestone Dec 15, 2016
@billti
Copy link
Member Author

billti commented Dec 15, 2016

Actually, looks like this was fixed a couple weeks back, but the LKG is out of date. I'll update that.

@billti
Copy link
Member Author

billti commented Dec 15, 2016

Updated the LKG which resolved this.

@billti billti closed this as completed Dec 15, 2016
@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
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants