Skip to content

Conversation

rbuckton
Copy link
Contributor

@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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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