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

Bug: a instanceof b === false doesn't influence type flow #53093

Closed
jeengbe opened this issue Mar 4, 2023 · 2 comments
Closed

Bug: a instanceof b === false doesn't influence type flow #53093

jeengbe opened this issue Mar 4, 2023 · 2 comments

Comments

@jeengbe
Copy link

jeengbe commented Mar 4, 2023

Bug Report

🔎 Search Terms

instanceof explicit false if type narrowing

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Common bugs that aren't bugs
  • I was able to reproduce this on versions 5.1.0-dev.20230304

⏯ Playground Link

Playground link with relevant code

💻 Code

declare const x: unknown;

() => {
    if(x instanceof Error === false) return;

       x;
    // ^?
    // Should be 'Error', is 'unknown'
}

() => {
    if(!(x instanceof Error)) return;

       x;
    // ^?
    // Is correctly 'Error'
}

🙁 Actual behavior

The semantically equivalent expressions (x instanceof Error === false) and !(x instanceof Error) influence type flow (correct term?) differently.

🙂 Expected behavior

(x instanceof Error === false) should function the same way !(x instanceof Error) does.

@jcalz
Copy link
Contributor

jcalz commented Mar 4, 2023

Duplicate of #31105 and #9508 (is this a bug or a won’t fix?)

@jeengbe jeengbe closed this as completed Mar 4, 2023
@jeengbe
Copy link
Author

jeengbe commented Mar 4, 2023

a won't fix, I wasn't aware of this limitation

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