Skip to content

Typeguard not working if checked against Exclude #49118

Description

Bug Report

🔎 Search Terms

typeguard exclude union

🕗 Version & Regression Information

v4.6.2

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about typeguards

⏯ Playground Link

Playground link with relevant code

💻 Code

type AAA = {
    c: 0
    b: 1
} | {
    c: Exclude<number, 0>
    x: 1
}

const a = {} as unknown as AAA

if (a.c !== 0) a.x

🙁 Actual behavior

error

Property 'x' does not exist on type 'AAA'.
  Property 'x' does not exist on type '{ c: 0; b: 1; }'.

🙂 Expected behavior

no error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions