-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Consistent narrowing by discriminant #38311
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
Conversation
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 88025e6. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the perf test suite on this PR at 88025e6. 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 88025e6. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 88025e6. You can monitor the build here. |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
@ahejlsberg Here they are:Comparison Report - master..38311
System
Hosts
Scenarios
|
Tests all look good (nothing but preexisting conditions). |
@weswigham I think it pretty much replaces the second: this is so much simpler. I don’t believe this is quite as general as the other PR aims to be, but I went through all the duplicates on the original issue and this fixes them. I think my only comment here is whether it’s worth filter the declared type for non-object types. I’m not sure this approach works if the declared type is something like The first PR you link was some tidying I haven’t updated yet (sorry). I don’t think it’s changed by this. |
With this PR we fix inconsistencies in our narrowing logic for discriminated unions. Previously we required the declared type of a reference to be a union type before we'd narrow by discriminants. This meant narrowing by discriminant wouldn't work in conjunction with user defined type predicate narrowing, with the notable (and inconsistent) exception of
switch
statements. We now consistently allow narrowing by discriminant of a reference with a declared type that isn't a union but a control flow type that is (which, for example, might result from first narrowing anunknown
to a union type using a user defined type predicate and then narrowing the union type by a discriminant).Fixes #30557.
Fixes #36777.