Open Woodz opened 4 months ago
This playground might also be helpful to see what is happening. The inverted narrowing works just fine:
function myFunction4(input: Foo | Bar | Baz) {
if (!("baz" in input)) {
input;
// ^? (parameter) input: Foo | Bar
} else {
input;
// ^? (parameter) input: Baz
}
}
The issue here is specific to the fact that inverted narrowing is used on the type is already refined using the same non-inverted check.
🔎 Search Terms
"union type", "narrowing", "inverted", "4.9"
🕗 Version & Regression Information
⏯ Playground Link
Playground link
💻 Code
🙁 Actual behavior
In 4.9.5 and later, in the else block,
input.foo
incorrectly narrows and errors🙂 Expected behavior
In 4.8.4 and earlier, in the else block,
input.foo
correctly narrowsAdditional information about the issue
No response