-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Closed
Copy link
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed