TypeScript Version: 4.1.3
Search Terms:
Expected behavior:
No error. The downlevel emit is fine, so this won't give any unexpected behavior at runtime.
Actual behavior:
Initializer of instance member variable '[a]' cannot reference identifier 'a' declared in the constructor.
Code
const a = Symbol();
class C {
[a] = 1;
constructor(a) {}
}
Output
"use strict";
var _a;
const a = Symbol();
class C {
constructor(a) {
this[_a] = 1;
}
}
_a = a;
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided