Skip to content
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

Narrow intersected classes using instanceof #51032

Closed
wants to merge 1 commit into from

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.

@sandersn sandersn added this to Not started in PR Backlog Oct 18, 2022
@sandersn sandersn moved this from Not started to Waiting on reviewers in PR Backlog Nov 15, 2022
@@ -17775,7 +17775,7 @@ namespace ts {
target.flags & TypeFlags.Union ? some((target as UnionType).types, t => isTypeDerivedFrom(source, t)) :
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
PR Backlog automation moved this from Waiting on reviewers to Done Nov 23, 2022
@Andarist Andarist deleted the fix/50844 branch November 23, 2022 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

instanceof does not narrow when the class is intersected with &
3 participants