Skip to content

False positive for TS2729 (use before initialization) in 3.8.3, nightly #37573

Closed
@Jessidhia

Description

@Jessidhia

TypeScript Version: 3.8.3, nightly

Search Terms: used before initialization

Code

Reproduction requires both --target esnext and --useDefineForClassFields to be enabled.

class Foo {
    constructor (readonly foo: boolean) {}
}

class Bar extends Foo {
    bar = this.calculateBar(this.foo)

    private calculateBar(positive: boolean) {
        return positive ? 1 : -1
    }
}

Expected behavior:

Code to build.

Even if TypeScript was doing some kind of flow analysis here (which could flag this.foo instead of this.calculateBar), Foo's constructor is guaranteed to finish executing before bar's initializer gets a chance to run; and a prototype method is never not initialized.

Actual behavior:

Property 'calculateBar' is used before its initialization.(2729)
input.ts(8, 13): 'calculateBar' is declared here.

Playground Link: Playground Link

Related Issues: This seems related to #37287, just happens on different conditions

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions