Skip to content

Fix instanceof use with Symbol.hasInstance in conjunction with union/intersection #57602

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

Merged
merged 1 commit into from
Mar 2, 2024

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Mar 1, 2024

This fixes an issue with control flow narrowing of instanceof when the right-hand side is either a union or intersection with a [Symbol.hasInstance] method. The original intent was that we would only use [Symbol.hasInstance] if it belonged to an object type, but the implementation didn't account for unions or intersections as getPropertyOfObjectType is specific to immediate object types only. This now instead performs the object type test separately prior to calling getPropertyOfType instead.

Fixes #56536

@rbuckton rbuckton requested review from sandersn and weswigham March 1, 2024 21:33
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 1, 2024
@rbuckton rbuckton merged commit ea0d228 into main Mar 2, 2024
@rbuckton rbuckton deleted the fix56536 branch March 2, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

instanceof does not respect inherited Symbol.hasInstance
3 participants