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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
MartinJohns commentedon May 19, 2022
See: https://github.com/microsoft/TypeScript/wiki/FAQ#what-is-structural-typing
Duplicate of #20863. Generally the excess-property check does not work for union types.
Kwongiseok commentedon May 19, 2022
I think In this case variable a must should pass type check Okay....
why 2 tagged union is okay??
typescript-bot commentedon May 23, 2022
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community.