-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix #6311 #6328
Fix #6311 #6328
Conversation
} | ||
const sourcePredicate = sourceReturnType as PredicateType; | ||
const targetPredicate = targetReturnType as PredicateType; | ||
if (sourcePredicate.predicate.kind === TypePredicateKind.Identifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't they both need to have the same predicate type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
So the idea is that a predicate type will always be assignable to a If so, I think this might be the way to go. |
@@ -5666,7 +5655,24 @@ namespace ts { | |||
} | |||
} | |||
|
|||
return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); | |||
result = result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a better idea to first check if they are both predicate types, since it doesn't look like you need to relate the return types in that case.
I think this approach is moving in the right direction, which is pushing more of the comparison burden on the signature instead of the type predicate. That said, I am still in favor of completely obliterating the type predicate as a type, and doing the full comparison on a signature basis. I don't understand how it is meaningful to compare type predicates at all, given that their meaning is entirely based on their signature of origin. |
I think there are merits to the current approach. Namely:
|
I agree about the second point, regarding
|
I think you're right that we could continue limiting to signatures, but I'd rather we went our course with how things are now, and revisit if there are other major issues that pop up. |
I do agree with @JsonFreeman that predicates do not belong in a type. this is leading to the current behavior. i am not sure i understand why something like |
@mhegazy where are you getting that example from? I don't think we ever said that should be an error, and with this change, it shouldn't be considered an error. |
I think it could be result in an error even with this change, because the type portions of the type predicates are still being compared. So if the types are different, it will be an error, though in my opinion it should not be. |
By moving predicate argument position comparison to signature comparison, since the compatibility of isolated predicate comparisons never hinges on argument position equality.
Thoughts? @JsonFreeman @DanielRosenwasser
Edit by @DanielRosenwasser: Fixes #6311