Skip to content

Multiple tagged union with undefined can't catch error  #49176

Closed
@Kwongiseok

Description

@Kwongiseok

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

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions