microsoft / microsoft/TypeScript
`tsc` with `--target ESNext` fails but the same configuration succeeds on the playground.
@armanio123 ci sta già lavorando.
Dal 2/8/2021.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.