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 operator not transpiled when used in a default value #35771

Closed
fzaninotto opened this issue Dec 19, 2019 · 1 comment · Fixed by #35872
Closed

Spread operator not transpiled when used in a default value #35771

fzaninotto opened this issue Dec 19, 2019 · 1 comment · Fixed by #35872
Assignees
Labels
Bug A bug in TypeScript

Comments

@fzaninotto
Copy link

TypeScript Version: 3.7.3 + online playground

Search Terms: spread, rest, object assign

Code

// A *self-contained* demonstration of the problem follows...
import arrayMutators from 'final-form-arrays';

const FormWithRedirect = ({
    mutators = { ...arrayMutators },
    ...props
}) => {
    console.log(mutators)
};

export default FormWithRedirect;

Expected behavior:

The spread operator in the default value for mutators ({ ...arrayMutators }) should be transpiled to Object.assign when the compilation target is ES5.

Actual behavior:

The transpiled code includes a spread operator, which isn't valid ES5:

var final_form_arrays_1 = __importDefault(require("final-form-arrays"));
var FormWithRedirect = function (_a) {
    var _b = _a.mutators, mutators = _b === void 0 ? { ...final_form_arrays_1.default } : _b, props = __rest(_a, ["mutators"]);
    console.log(mutators);
};
exports.default = FormWithRedirect;

Playground Link: https://www.typescriptlang.org/play/index.html?target=1&jsx=2&module=1&ssl=11&ssc=1&pln=1&pc=1#code/JYWwDg9gTgLgBAQylBBPAsgVxgm0DOcAZlBCHAORHAB2CANgLRHQiNIqr4UDcAUHwDGEGvngAxVgHVgMABYAlAKYATYFCWD4AXjgAKAN584JuCGy4CcXQbgA6BxzRYceKIQC+AGmOmHdsFIwfD4PAEprAD44I1M4YVEIeiU7eggAcz1zVwIw0P4+JQAPSFg4FSUiBEx6CWlZRVV1TRh+IA

Related Issues: None

@ajafff
Copy link
Contributor

ajafff commented Dec 27, 2019

Fix is up at #35872

rbuckton pushed a commit that referenced this issue Jan 24, 2020
…turing with rest (#35872)

* es2018: visit other binding elements when transforming object destructuring with rest

fixes: #35771

* more tests
JulienMattiussi pushed a commit to marmelab/react-admin that referenced this issue Jan 28, 2020
JulienMattiussi pushed a commit to marmelab/react-admin that referenced this issue Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
4 participants