Closed
Description
TypeScript Version: 3.9.0-dev.20200306
Search Terms:
successive type guards, conditional type guards, type guards
Code
function isNull(a: string | null): a is null {
return a == null;
}
function doStuff(a: string | null, b: string | null) {
if (a == null && b == null) {
return;
}
if (a == null && b != null) {
return;
}
if (a != null && b == null) {
return;
}
a; // logically must be `string`, but inferred as `string | null`
b; // logically must be `string`, but inferred as `string | null`
a.length; // Object is possibly 'null'
}
Expected behavior:
a
and b
cannot logically be null, therefore it should be inferred that these are strings.
Actual behavior:
It is inferred that these variables are possibly null.
Related Issues:
#9016