-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 4.0.0-dev.20200803
Search Terms:
discriminated union
union
type predicate
type guard
narrow
Code
interface A {
kind: "A";
foo?: string;
}
interface AA extends A {
foo: string;
}
interface B {
kind: "B";
foo: string;
}
interface BB extends B {
//blah: string; // comment or uncomment this line
}
function isDefiniteFoo(x: A | B) : x is AA | BB {
return !!x.foo;
}
let x!: A | B;
if (isDefiniteFoo(x)) {
// Without line 16, the type of x is narrowed to B
// If line 16 is present, the type of x is narrowed to AA | BB
let z = x;
// Note that BB isn't required to expose the bug. If the return type on
// isDefiniteFoo is : x is AA | B, x is still narrowed to B rather than AA | B
}
Expected behavior:
The type of x
should be narrowed to AA | BB
.
Actual behavior:
The type of x
is narrowed to B
.
minchingtonak
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created