-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Infer type arguments on instance check #58028
base: main
Are you sure you want to change the base?
Infer type arguments on instance check #58028
Conversation
9b2769e
to
49747b0
Compare
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
The TypeScript team hasn't accepted the linked issue #17473. If you can get it accepted, this PR will have a better chance of being reviewed. |
1 similar comment
The TypeScript team hasn't accepted the linked issue #17473. If you can get it accepted, this PR will have a better chance of being reviewed. |
@typescript-bot test it |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos comparing Something interesting changed - please have a look. Details
|
Wow, it broke approximately everything 😅 |
Not surprising if you've seen #49863. Notably, this new PR adds a strict mode setting. That's what made DT clean, as DT does not set |
@jakebailey If you pack this I can make playground reproductions of some of these errors. And let me know if you want to test turning it on by default 😅 |
@typescript-bot pack this |
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 |
There are a decent number of errors where some type that was A) Extracting
|
49747b0
to
fcab6eb
Compare
fcab6eb
to
26df4e9
Compare
Fixes #17473 - Infer constrained generic parameters after instanceof check
Fixes #46668 - Private field check narrows generic class too far
This is an updated and ready-to-be-reviewed recreation of my previous #49863. Please see that PR for a longer description of the problem and the proposed solution, as I don't want to duplicate it all here unnecessarily. In short, when instantiating the type of a class for an instance check, TypeScript would populate all type arguments with
any
no matter the constraint on the type parameter or the strictness settings. This change factors in the compiler strictness as well as the constraints and variances of the type parameters to "infer" the type arguments.This does NOT handle #57317, per @Andarist on #57323 but I have included that test case here as these changes do introduce new behavior to that case (
any
tounknown
). I can remove if it feels irrelevant to these changes.Breaking Changes
From the last PR, I have resolved to use the compiler option
strictInstanceOfTypeParameters
to gate these otherwise breaking changes. However, there was some discussion about the possibility of not hiding these changes behind a compiler option. I can test enabling these changes for all, similar to what I did last time.