Skip to content

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

@fzaninotto

Description

@fzaninotto

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

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