Make anyFunctionType a subtype of all function types#1149
Merged
jakebailey merged 3 commits intomainfrom Jun 10, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
signaturesRelatedToto treatanyFunctionTypeas a subtype (but not a supertype) of functions. - Updates test baselines to reflect that callbacks inferred from
useMemonow have parameter typeanyand trigger an implicit-any error. - Adjusts symbol and error snapshots to expect
anyfor 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 |
| } | ||
| 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.
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.
Suggested change
| 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 | |
| } | |
| } | |
| } |
jakebailey
approved these changes
Jun 10, 2025
This was referenced Feb 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements what I discuss here.
Fixes #1016.