-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
π Search Terms
discriminated union never, discriminating property never
π Version & Regression Information
It happens in every version I tried.
β― Playground Link
π» 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
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript