microsoft / microsoft/TypeScript
`tsc` with `--target ESNext` fails but the same configuration succeeds on the playground.
@armanio123 arbeitet bereits daran.
Seit 02.8.2021.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
tsc causes errors for --target ESNext for some order of initialized variables and variables initialized in the constructor.
Why does the code produce errors for ESNext and no error for any other target?
🔎 Search Terms
- ESNext
🕗 Version & Regression Information
The command line fails on the code where the playground succeeds.
⏯ Playground Link
You have to set the --target to ESNext for this script Playground link with relevant code
💻 Code
Compiling this code with
./node_modules/.bin/tsc --target ESNext x.ts
function writeVal(a: number, b: any): number {
console.log(‘writeVal’, a, b);
return a;
}
class TestClass {
a: number;
public b = writeVal(2, this.z);
constructor(public z: number) {
this.a = writeVal(1, this.z);
}
public c = writeVal(3, this.z);
}
I get the following error:
x.ts:7:33 - error TS2729: Property ‘z’ is used before its initialization.
7 public b = writeVal(2, this.z);
~
x.ts:8:17
8 constructor(public z: number) {
~~~~~~~~~~~~~~~~
‘z’ is declared here.
x.ts:11:33 - error TS2729: Property ‘z’ is used before its initialization.
11 public c = writeVal(3, this.z);
~
x.ts:8:17
8 constructor(public z: number) {
~~~~~~~~~~~~~~~~
‘z’ is declared here.
Found 2 errors.
🙁 Actual behavior
Running the code above in the playground there is no error, but tsc throws errors and fails to compile.
🙂 Expected behavior
Playground and the compiler should produce the same errors.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.