Closed
Description
Bug Report
TypeScript can't catch error about Multiple tagged union (more 3 tagged union) with undefined
🔎 Search Terms
Multiple tagged union , tagged union with undefined , undefined union
🕗 Version & Regression Information
TypeScript Version : 4.6
Please keep and fill in the line that best applies:
-->
- This is a bug
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
type T = 1 | 2 | 3
interface P {
a: T
}
interface A extends P {
a: 1
b: undefined
}
interface B extends P {
a: 2
b: number
}
interface C extends P {
a: 3
}
type Q = A | B | C
const a: Q = { a: 1, b: 1 } // Good : TypeScript catch error, b must be undefined
const c: Q = { a: 3, b: 1 } // Bad : TypeScript didn't catch any error, TS compiler passed it.
🙁 Actual behavior
variable a is error
variable c is not error
🙂 Expected behavior
I expected variable c is error when a is 3 variable b shouldn't exits