Closed
Description
TypeScript Version: 2.1.5
Code
type MyType = {
arguments: Array<string>
}
function myFunction(myType: MyType) {
for (let i = 0; i < 10; i++) {
console.log(myType.arguments[i]);
// create closure so that tsc will turn loop body into function
const x = 5;
[1, 2, 3].forEach(function(j) {
console.log(x);
})
}
}
export { myFunction };
Expected behavior:
myType.arguments[i]
is left unmodified or translated to something equivalent
Actual behavior:
myType.arguments[i]
becomes myType.arguments_1[i]
.
"use strict";
function myFunction(myType) {
var _loop_1 = function (i) {
console.log(myType.arguments_1[i]);
// create closure so that tsc will turn loop body into function
var x = 5;
[1, 2, 3].forEach(function (j) {
console.log(x);
});
};
var arguments_1 = arguments;
for (var i = 0; i < 10; i++) {
_loop_1(i);
}
}
exports.myFunction = myFunction;
ES5 permits keywords to be used as object properties.
If in aspiring to be a superset of javascript, typescript also wants to allow keywords to be used as object properties, then myType.arguments[i]
should stay unchanged or become something equivalent. If not, then typescript should raise an error. Currently no error is raised, and incorrect javascript is generated.