Skip to content

rest args are busted #12956

Closed
Closed
@billti

Description

@billti

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions