-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Fixed an issue with in
not being able to be used on narrowed down expression of a generic nullable type
#51502
Fixed an issue with in
not being able to be used on narrowed down expression of a generic nullable type
#51502
Conversation
…xpression of a generic nullable type
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.
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)); | ||
} |
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.
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.
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.
Nice, I've pushed out the requested change.
Could/should this be cherry picked to 4.9 branch? |
fixes #51501
fixes #51549