Closed
Description
If a class constructor calls another method, references in that method are not checked for initialization.
TypeScript Version: 4.0.3
Search Terms: false negative null undefined used before being assigned
Code
class B {
public foo() {}
}
class C {
private b: B;
constructor() {
this.reset();
this.b = new B();
}
private reset() {
this.b.foo(); // false negative - `b` used before being assigned
}
}
Expected behavior: error: b
used before being assigned
Actual behavior: no error
Related Issues:
Note that this problem can be solved (mostly) with this: #30462
That issue talked about a false positive, but this false negative is also a problem that could be solved with the same solution.
It can't be solved completely because of possible complexities in structures.
But I ran into a null pointer exception that would have been caught by TypeScript if it just followed a simple single level of function calls.