Skip to content

Constructor code broken since npm version 4.3.0-dev.20210408 with --target ESNext #45298

@scharf

Description

@scharf

Bug Report

Compiling the code below compiled with the --target ESNext option, an error is thrown.

🕗 Version & Regression Information

  • No problem up to npm version 4.3.0-dev.20210407
  • The problem first appears in npm version 4.3.0-dev.20210408

⏯ Playground Link

Cannot be reproduced in the playground (see #45297)

💻 Code

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);
}

🙁 Actual behavior

throws

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.

🙂 Expected behavior

The created javascript file should be

function writeVal(a, b) {
    console.log('writeVal', a, b);
    return a;
}
class TestClass {
    constructor(z) {
        this.z = z;
        this.b = writeVal(2, this.z);
        this.c = writeVal(3, this.z);
        this.a = writeVal(1, this.z);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions