I have the following typescript:
var mynames = new Array<string>();
mynames.push("Currency");
mynames.push("School_Id");
for (const mn of mynames) {
console.log(mn);
}
Which is compiled into javascript:
var mynames = new Array();
mynames.push("Currency");
mynames.push("School_Id");
for (const mn of mynames) {
console.log(mn);
}
Which is minified to:
n = [
];
n.push('Currency');
n.push('School_Id');
for (const n of n) console.log(n);
Which causes the exception:
Uncaught ReferenceError: can't access lexical declaration 'n' before initialization
Why am I getting an error when the code has been minified and not before?
You are defining a variable with the same name with the array variable. use another name like:
for (const m of n) console.log(n);