Skip to content

Conversation

@Andarist
Copy link
Contributor

@Andarist Andarist commented Nov 12, 2022

fixes #51501
fixes #51549

Copy link
Member

@ahejlsberg ahejlsberg left a 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.

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));
}
Copy link
Member

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.

Copy link
Contributor Author

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.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 21, 2022
@Andarist Andarist requested a review from ahejlsberg November 21, 2022 13:26
@ahejlsberg ahejlsberg merged commit 5cd2d97 into microsoft:main Nov 22, 2022
@Andarist Andarist deleted the fix/in-against-nullable-generic-constraint branch November 22, 2022 06:08
@HolgerJeromin
Copy link
Contributor

Could/should this be cherry picked to 4.9 branch?

@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

4 participants