Closed
Description
Bug Report
π Search Terms
private field, class, narrow, narrowing
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground link with relevant code
π» Code
class TestClass {
#privateProperty: string[] | null;
publicProperty: string[] | null;
constructor() {
this.#privateProperty = null;
this.publicProperty = null;
}
testMethod() {
if (this.#privateProperty === null)
return;
if (this.publicProperty === null)
return;
this.#privateProperty; // string[] | null
this.publicProperty; // string[]
const a = this.#privateProperty;
a; // string[]
}
}
π Actual behavior
this.#privateProperty
is string[] | null
even after narrowing down the type from if
. Also assigning this.#privateProperty
to other variable fixes the type.
π Expected behavior
this.#privateProperty
should be string[]
after narrowing down