-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
π Search Terms
"infer", "undefined", "compound", "boolean expression"
π Version & Regression Information
i dont know if this is changed behaviour
β― Playground Link
π» Code
interface Test {
t: string | undefined;
}
function testFunc(a: Test, b: boolean){
// Problem case
if (b && !a.t) {
console.log('if')
} else {
// INCORRECT - not undefined should be inferred
const b = a.t.indexOf('1');
}
// Working case
if (b && a.t) {
// CORRECT - not undefined inferred
const b = a.t.indexOf('1');
}
// Working case
if (!a.t) {
//
} else {
// CORRECT - not undefined inferred
const b = a.t.indexOf('1');
}
}
π Actual behavior
a.t was checked to be undefined by if, but in else it is not inferred.
in test case 1, we can see that doing the reverse (checking for defined and checking in "if" for defined works correctly)
in test case 2, we can see that if its not a compound boolean expression it works correctly
π Expected behavior
inferred type in else should be defined because it was checked in the if
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug