Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeguard not working if checked against Exclude #49118

Closed
qwelias opened this issue May 15, 2022 · 3 comments
Closed

Typeguard not working if checked against Exclude #49118

qwelias opened this issue May 15, 2022 · 3 comments

Comments

@qwelias
Copy link

qwelias commented May 15, 2022

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

@MartinJohns
Copy link
Contributor

The type Exclude<number, 0> is exactly the same type as number. It does not do what you think it does. There is no way to represent a type "any number, except 0" in TypeScript. This would first require #29317.

@qwelias
Copy link
Author

qwelias commented May 15, 2022

thanks, tho it's been open for 3+yrs now...

@qwelias qwelias closed this as completed May 15, 2022
@MartinJohns
Copy link
Contributor

It's a fairly difficult issue to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants