Closed as not planned
Description
The TypeScript compiler generates the following code for rest arguments:
function foo(x, y, z, ...rest) {
return;
}
function foo(x, y, z) {
var rest = [];
for (var i = 0; i < arguments.length - 3; i++) {
rest[i] = arguments[i + 3];
}
return;
}
Although rest
is unused in the body of the function, JS engines can't easily dead code eliminate the allocation of the rest
array and the subsequent for loop due to the possibility of Array.prototype being mutated:
Object.defineProperty(Array.prototype, 42, { set: function() { alert(this[41]); }});
It's much easier for the TypeScript compiler to avoid emitting this code when it is not necessary.
See more details: