🔎 Search Terms
discriminated union never, discriminating property never
🕗 Version & Regression Information
It happens in every version I tried.
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241206#code/C4TwDgpgBAIglgZwMYFUB2cD2aoF4BQAPlAN5QAmiSACgE6ZgBcUaEAbhLQDRQCGzARigBfIqQpU6DZgCIw9MDJ4AjZgCYRYspWRSmUAK5pyEAGZxW5HkmYBmTfhNIANr1rQk2BMCiZm8ZHQsNHx8OFMACkwAOh0aBQBKUnwoXxSoAHoMqAA9AH58YSgIZwRoEnTMdKzcgtEwyIBCGLi9JIrUqtSa-MLi0vLK6uze4SA
💻 Code
type DiscUnion =
| { discProp: never, a: 1 }
| { discProp: "prop", b: 2 }
| { discProp: undefined, c: 3 }
declare const o: DiscUnion
if(o.discProp) {
o
// ^? { discProp: "prop"; b: 2; }
} else {
o
// ^? { discProp: undefined; c: 3; }
}
if(!o.discProp) {
o
// ^? { discProp: undefined; c: 3; }
} else {
o
// ^? { discProp: "prop"; b: 2; }
}
🙁 Actual behavior
{ discProp: never, a: 1 } disappears!
🙂 Expected behavior
In the first if, I expect { discProp: never, a: 1 } to be a possible type of o in the else branch. Viceversa, in the second if I expect it to be a possible type of o in the then branch.
Additional information about the issue
No response
🔎 Search Terms
discriminated union never, discriminating property never
🕗 Version & Regression Information
It happens in every version I tried.
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241206#code/C4TwDgpgBAIglgZwMYFUB2cD2aoF4BQAPlAN5QAmiSACgE6ZgBcUaEAbhLQDRQCGzARigBfIqQpU6DZgCIw9MDJ4AjZgCYRYspWRSmUAK5pyEAGZxW5HkmYBmTfhNIANr1rQk2BMCiZm8ZHQsNHx8OFMACkwAOh0aBQBKUnwoXxSoAHoMqAA9AH58YSgIZwRoEnTMdKzcgtEwyIBCGLi9JIrUqtSa-MLi0vLK6uze4SA
💻 Code
🙁 Actual behavior
{ discProp: never, a: 1 }disappears!🙂 Expected behavior
In the first
if, I expect{ discProp: never, a: 1 }to be a possible type ofoin theelsebranch. Viceversa, in the secondifI expect it to be a possible type ofoin thethenbranch.Additional information about the issue
No response