Skip to content

Falsy instanceof check doesn't affect righthand or expression #55395

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

Closed
LeviticusMB opened this issue Aug 16, 2023 · 3 comments
Closed

Falsy instanceof check doesn't affect righthand or expression #55395

LeviticusMB opened this issue Aug 16, 2023 · 3 comments

Comments

@LeviticusMB
Copy link

πŸ”Ž Search Terms

instanceof or unknown

πŸ•— Version & Regression Information

  • Didn't think of it until 4.4 when caught values became unknown, but the actual problem has probably been present for a long time.

See #38309, for instance.

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.0-beta#code/MYGwhgzhAEDqCmAjAogJ1Qe1deAPALvAHYAmMAqgEoCSam2A3gLABQ070E+Y+ArhAH4AXNCK8AtonioA3KwC+rVvlQBPaMzYcA9NugBZMAGt40MNFTwAjr3hcF0YD2AALaAAppqAJQbWHaABLADMPLyCiLjAiYHgMUIQUdCxoAF506GCwEAhTAB88nHQAOii+GABCVOgAFgAGAEZfTQCA4AxIjBB4Yq8sT3RvOS12RRYxoA

πŸ’» Code

class WebError extends URIError {
    status?: number;
}

try {
    // Make a request
} catch (err) {
    if (err instanceof WebError === false || err.status != 401) {
        console.error(err);
    }
}

πŸ™ Actual behavior

The compiler thinks err is unknown and does not understand that err.status must be a valid property.

πŸ™‚ Expected behavior

No compiler error.

Additional information about the issue

No response

@Andarist
Copy link
Contributor

=== false variant should start working once this PR lands: #53714

@LeviticusMB
Copy link
Author

Oh I see, it was just because of the === false part ... I always write it like that because those extra parentheses annoy me.

Thanks for the tip.

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

3 participants