Fixed an issue with in not being able to be used on narrowed down expression of a generic nullable type#51502
Merged
ahejlsberg merged 3 commits intomicrosoft:mainfrom Nov 22, 2022
Conversation
…xpression of a generic nullable type
ahejlsberg
requested changes
Nov 21, 2022
Member
ahejlsberg
left a comment
There was a problem hiding this comment.
It's the right fix, but shorter with the suggested change.
src/compiler/checker.ts
Outdated
| const constraint = getBaseConstraintOfType(rightType); | ||
| if (!constraint || isEmptyAnonymousObjectType(constraint)) { | ||
| error(right, Diagnostics.Type_0_may_represent_a_primitive_value_which_is_not_permitted_as_the_right_operand_of_the_in_operator, typeToString(rightType)); | ||
| } |
Member
There was a problem hiding this comment.
Instead of adding these lines of code, I'd suggest modifying hasEmptyObjectIntersection to
function hasEmptyObjectIntersection(type: Type): boolean {
return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && isEmptyAnonymousObjectType(getBaseConstraintOrType(t)));
}Accomplishes the same thing with less code.
Contributor
Author
There was a problem hiding this comment.
Nice, I've pushed out the requested change.
ahejlsberg
approved these changes
Nov 21, 2022
Contributor
|
Could/should this be cherry picked to 4.9 branch? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #51501
fixes #51549