TypeScript/tests/cases/compiler/narrowingOrderIndependent.ts
Anders Hejlsberg a5796cf3b2
Remove ordering restrictions in control flow analysis (#37134)
* Don't reset CFA type for x.y when x is narrowed

* Add tests

* Accept new baselines

* Remove unnecessary type assertion
2020-02-29 12:03:09 -08:00

34 lines
579 B
TypeScript

// @strict: true
// Repro from #36709
class A {
constructor(public stringOrUndefined: string | undefined) {}
}
class B {
constructor(public str: string) {}
}
const a = new A("123");
if (a instanceof A && a.stringOrUndefined) {
new B(a.stringOrUndefined)
}
if (a.stringOrUndefined && a instanceof A) {
new B(a.stringOrUndefined)
}
if (a instanceof A) {
if (a.stringOrUndefined) {
new B(a.stringOrUndefined)
}
}
if (a.stringOrUndefined) {
if (a instanceof A) {
new B(a.stringOrUndefined)
}
}