Closed
Description
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