-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Disallow instantiation expressions on the right side of instanceof #53323
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
Disallow instantiation expressions on the right side of instanceof #53323
Conversation
@typescript-bot test this |
Heya @jakebailey, I've started to run the extended test suite on this PR at 3478a4c. You can monitor the build here. |
Heya @jakebailey, I've started to run the tarball bundle task on this PR at 3478a4c. You can monitor the build here. |
Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at 3478a4c. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at 3478a4c. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the abridged perf test suite on this PR at 3478a4c. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at 3478a4c. You can monitor the build here. Update: The results are in! |
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
@jakebailey Here are the results of running the user test suite comparing Everything looks good! |
~~~~~~~~~~~ | ||
!!! error TS2848: The right-hand side of an 'instanceof' expression must not be an instantiation expression. | ||
|
||
Box<number> instanceof Object; // OK |
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.
I am checking only the right side here, but, should these even be legal? They seem useless in another way.
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.
Is the instantiation expression pointless? Yes. Is it harmful? No. Is it misleading? Probably not really on the LHS, since the only reason I can think of why you'd want one on the LHS is to "satisfy" the RHS, but the RHS forbids them now, soooo...
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.
Yeah. I don't really care either way. I guess this PR is fine as-is.
@jakebailey Here they are:Comparison Report - main..53323
System
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top-repos suite comparing Everything looks good! |
Hey @jakebailey, the results of running the DT tests are ready. |
In reviewing #49863, we noticed that we don't emit any sort of error when you use an instantiation expression on the right side of an instanceof check. E.g. in the below code,
<number>
does nothing; you'll still getany
.Playground Link
This PR disallows this syntactically.
We could try and figure out how to do:
And that fix would look different.