Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Make anyFunctionType a subtype of all function types - #1149

Merged
Jake Bailey (jakebailey) merged 3 commits into
mainfrom
fix-1016
Jun 10, 2025
Merged

Make anyFunctionType a subtype of all function types#1149
Jake Bailey (jakebailey) merged 3 commits into
mainfrom
fix-1016

Conversation

@ahejlsberg

Copy link
Copy Markdown
Member

Implements what I discuss here.

Fixes#1016.

CopilotAI review requested due to automatic review settings June 10, 2025 13:11

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 treat anyFunctionType as a subtype (but not a supertype) of functions.
  • Updates test baselines to reflect that callbacks inferred from useMemo now have parameter type any and trigger an implicit-any error.
  • Adjusts symbol and error snapshots to expect any for parameter x.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

FileDescription
internal/checker/relater.goAdded checks to return TernaryTrue/TernaryFalse for anyFunctionType subtyping
testdata/baselines/reference/compiler/subtypeReductionWithAnyFunctionType.typesUpdated expected type prints to (x: any) => boolean
testdata/baselines/reference/compiler/subtypeReductionWithAnyFunctionType.symbolsAdjusted symbol entries so x is declared with type any
testdata/baselines/reference/compiler/subtypeReductionWithAnyFunctionType.errors.txtNow 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 {

CopilotAIJun 10, 2025

Copy link

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.

Suggested change
ifsource==r.c.anyFunctionType {
ifsource==r.c.anyFunctionType {
sourceSignatures:=r.c.getSignaturesOfType(source, kind)
targetSignatures:=r.c.getSignaturesOfType(target, kind)
for_, s:=rangesourceSignatures {
for_, t:=rangetargetSignatures {
ifr.signatureRelatedTo(s, t, true/*erase*/, reportErrors, intersectionState) ==TernaryFalse {
returnTernaryFalse
}
}
}

Copilot uses AI. Check for mistakes.
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discrepancy inferring function parameter from context

4 participants

@ahejlsberg@jakebailey