-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Narrow from 'any' in most situations #10334
Conversation
instanceof and user-defined typeguards narrow from 'any' unless the narrowed-to type is exactly 'Object' or 'Function'. This is a breaking change.
Hi @yortus, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
Existential crisis averted. Clearly it's because this PR title starts with an uppercase 'N'. |
👍 and an extra 🍺 for updating the comments in the testcases |
|
||
else if (err instanceof Error) { | ||
err.message; | ||
err.massage; // ERROR: Property 'massage' does not exist on type 'Error' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only errors came with massages.
Thanks for the change along with those test cases! |
Thanks for the guidance. |
Supersedes #10319 which has weird CI build problems.
This PR implements narrowing from
any
as described in #9999 (comment).NB: this is a breaking change.
Fixes #9999, #10000, #8677
Checklist:
instanceof
or a user-defined type predicate will narrow unless the narrowed-to type is exactlyFunction
or exactlyObject
(in which case the expression remains of typeany
)jake runtests
locally