Skip to content

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Oct 2, 2022

fixes #50844

  1. the logic was exiting from handling the intersection based on this isTypeDerivedFrom check here in the narrowTypeByInstanceof
  2. isTypeDerivedFrom was not happy about the source state because it wasn't an object type, it was an intersection. So I've adjusted the check here
  3. I added intersection handling to isFunctionObjectType as that seemed cleaner to me.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Oct 2, 2022
source.flags & TypeFlags.InstantiableNonPrimitive ? isTypeDerivedFrom(getBaseConstraintOfType(source) || unknownType, target) :
target === globalObjectType ? !!(source.flags & (TypeFlags.Object | TypeFlags.NonPrimitive)) :
target === globalFunctionType ? !!(source.flags & TypeFlags.Object) && isFunctionObjectType(source as ObjectType) :
target === globalFunctionType ? isFunctionObjectType(source) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue isn't just with x instanceof Function checks, it also extends to x instanceof Object checks. I have a more general solution to the problem in #51631.

@Andarist
Copy link
Contributor Author

Closing as superseded by #51631

@Andarist Andarist closed this Nov 23, 2022
@Andarist Andarist deleted the fix/50844 branch November 23, 2022 08:12
@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 Backlog Bug PRs that fix a backlog bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

instanceof does not narrow when the class is intersected with &

3 participants