-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Bring typeof switch closer inline with if #27680
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
Bring typeof switch closer inline with if #27680
Conversation
@@ -15317,6 +15317,32 @@ namespace ts { | |||
return caseType.flags & TypeFlags.Never ? defaultType : getUnionType([caseType, defaultType]); | |||
} | |||
|
|||
function getTypeFromName(type: Type, text: string) { |
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.
Would prefer a more descriptive name like getNarrowedTypeByTypeofResult
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.
Went with getImpliedTypeFromTypeofCase
to be consistent with terminology used in the documentation of narrowBySwitchOnTypeOf
.
@typescript-bot test this |
Heya @RyanCavanaugh, I've started to run the extended test suite on this PR at b12ed40. You can monitor the build here. It should now contribute to this PR's status checks. |
- Narrow unknown - Narrow union members (in addition to filtering)
b12ed40
to
b63b40b
Compare
@typescript-bot test this but again since it was edited (it passed before, so it should be fine, but just in case~) |
Heya @weswigham, I've started to run the extended test suite on this PR at b63b40b. You can monitor the build here. It should now contribute to this PR's status checks. |
This PR brings
switch
narrowing withtypeof
closer inline withif
, which was recently updated in two keys ways:Function
, the latterobject | null
.Fixes #27180
Fixes #27335
Adds tests for #27181