Closed
Description
Bug Report
🔎 Search Terms
intersection with discriminated union
This might be a duplicate of #33654 but I'm not completely sure. This issue has a simpler example anyway.
It also seems to be a duplicate of #9919 which was reportedly fixed. This is either regression or a missed case.
🕗 Version & Regression Information
- This is the behavior in every version I tried (v3.3 and v4.5), and I reviewed the FAQ for entries about intersection with discriminated union.
⏯ Playground Link
Playground link with relevant code
💻 Code
type X = ({ a: string } | { b: number }) & { a: unknown };
type Y = X["a"]; // actual: unknown, expected: string
🙁 Actual behavior
type Y
is unknown
.
🙂 Expected behavior
type Y
should be string
.
Why:
- When discriminating
{ a: string } | { b: number }
with "a
must be defined as a field", we get{ a: string }
. { a: string } & { a: unknown }
can be simplified to{ a: string }