-
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
Improve narrowing logic for instanceof
, type predicate functions, and assertion functions
#49625
Conversation
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at fc81aff. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at fc81aff. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at fc81aff. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at fc81aff. You can monitor the build here. |
@ahejlsberg Here they are:Comparison Report - main..49625
System
Hosts
Scenarios
Developer Information: |
Heya @ahejlsberg, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here. |
@ahejlsberg |
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at 37bfa91. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at 37bfa91. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 37bfa91. You can monitor the build here. |
@ahejlsberg |
Heya @ahejlsberg, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here. |
@typescript-bot pack this |
Heya @RyanCavanaugh, I've started to run the tarball bundle task on this PR at 37bfa91. You can monitor the build here. |
@ahejlsberg Here they are:Comparison Report - main..49625
System
Hosts
Scenarios
Developer Information: |
Hey @RyanCavanaugh, 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 |
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 960ad11. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at 960ad11. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 960ad11. You can monitor the build here. |
@ahejlsberg |
Heya @ahejlsberg, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here. |
Is this for the 4.8 RC, or is this waiting for 4.9? (Wondering because I was hoping to make this main's LKG as it might fix a few workarounds I have on my "enable strictFunctionTypes" branch.) |
microsoft/TypeScript#49625 improves handling of unions in type predicates so that unions are correctly preserved. This breaks types.isMap in node. For now I just changed the tests' expected type, but the type of isMap doesn't make much sense to me. It should probably be changed, but that's a much more complex task. This break is tracked at microsoft/TypeScript#49988 although it's correct, I think, so not very likely to be reverted.
* Update node types.isMap tests microsoft/TypeScript#49625 improves handling of unions in type predicates so that unions are correctly preserved. This breaks types.isMap in node. For now I just changed the tests' expected type, but the type of isMap doesn't make much sense to me. It should probably be changed, but that's a much more complex task. This break is tracked at microsoft/TypeScript#49988 although it's correct, I think, so not very likely to be reverted. * Change test for isSet too
TS 4.8 improves narrowing of type predicates when a union is passed in. This changes the return type of a couple of underscore and weak-napi functions. For now I just updated the tests, since underscore's change is pretty minor. And weak-napi's types probably need to be rewritten substantially, which would probably result in fixing this change. See microsoft/TypeScript#49625 for the change.
TS 4.8 improves narrowing of type predicates when a union is passed in. This changes the return type of a couple of underscore and weak-napi functions. For now I just updated the tests, since underscore's change is pretty minor. And weak-napi's types probably need to be rewritten substantially, which would probably result in fixing this change. See microsoft/TypeScript#49625 for the change.
This PR improves our narrowing logic for
instanceof
, type predicate functions, and assertion functions. In particular, we now correctly handle situations where the narrowing target type is a union type.Some examples:
Previously all of the above examples produced wrong results.
Fixes #31156.
Fixes #35953.
Fixes #37807.
Fixes #38869.
Fixes #39105.
Fixes #40035.
Fixes #41871.
Fixes #42101.
Fixes #43825.
Fixes #44754.
Fixes #46909.
Fixes #49588.