-
Notifications
You must be signed in to change notification settings - Fork 649
Make anyFunctionType
a subtype of all function types
#1149
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
Conversation
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.
Pull Request Overview
Introduces anyFunctionType
as a wildcard subtype of all other function types, updating signature relation logic and test baselines.
- Adds early-return logic in
signaturesRelatedTo
to treatanyFunctionType
as a subtype (but not a supertype) of functions. - Updates test baselines to reflect that callbacks inferred from
useMemo
now have parameter typeany
and trigger an implicit-any error. - Adjusts symbol and error snapshots to expect
any
for parameterx
.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
internal/checker/relater.go | Added checks to return TernaryTrue /TernaryFalse for anyFunctionType subtyping |
testdata/baselines/reference/compiler/subtypeReductionWithAnyFunctionType.types | Updated expected type prints to (x: any) => boolean |
testdata/baselines/reference/compiler/subtypeReductionWithAnyFunctionType.symbols | Adjusted symbol entries so x is declared with type any |
testdata/baselines/reference/compiler/subtypeReductionWithAnyFunctionType.errors.txt | Now reports a TS7006 implicit-any error for parameter x |
@@ -4359,9 +4359,13 @@ func (r *Relater) signaturesRelatedTo(source *Type, target *Type, kind Signature | |||
if r.relation == r.c.identityRelation { | |||
return r.signaturesIdenticalTo(source, target, kind) | |||
} | |||
if target == r.c.anyFunctionType || r.relation != r.c.strictSubtypeRelation && source == r.c.anyFunctionType { | |||
// With respect to signatures, the anyFunctionType wildcard is a subtype of every other function type. | |||
if source == r.c.anyFunctionType { |
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.
The unconditional TernaryTrue
when source
is anyFunctionType
bypasses signature checks (including return types), which could incorrectly mark incompatible function signatures as subtypes. Consider preserving return-type compatibility or narrowing the early return condition.
if source == r.c.anyFunctionType { | |
if source == r.c.anyFunctionType { | |
sourceSignatures := r.c.getSignaturesOfType(source, kind) | |
targetSignatures := r.c.getSignaturesOfType(target, kind) | |
for _, s := range sourceSignatures { | |
for _, t := range targetSignatures { | |
if r.signatureRelatedTo(s, t, true /*erase*/, reportErrors, intersectionState) == TernaryFalse { | |
return TernaryFalse | |
} | |
} | |
} |
Copilot uses AI. Check for mistakes.
Implements what I discuss here.
Fixes #1016.