Skip to content

Typeguard not working if checked against ExcludeΒ #49118

Closed
@qwelias

Description

@qwelias

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