Port anyFunctionType subtype fix and JSX children NonInferrableType propagation from typescript-go#63163
Port anyFunctionType subtype fix and JSX children NonInferrableType propagation from typescript-go#63163
Conversation
…NonInferrableType propagation Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
|
@typescript-bot test this |
There was a problem hiding this comment.
Pull request overview
Ports two TypeScript type-checker fixes from typescript-go into the main compiler: (1) correct subtype reduction behavior involving the internal anyFunctionType wildcard, and (2) ensure JSX children spread types propagate NonInferrableType so context-sensitive discrimination works for generic JSX component signatures.
Changes:
- Update signature relatedness so
anyFunctionTypeis treated as a subtype (source) but not as a supertype (target) of other function types. - Propagate
getPropagatingFlagsOfTypes(childrenTypes)into the object flags passed togetSpreadTypewhen synthesizing JSXchildren. - Add new compiler regression tests and reference baselines covering the subtype reduction and JSX children inference scenarios.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/compiler/checker.ts | Adjusts anyFunctionType signature relatedness semantics; propagates children flags (incl. NonInferrableType) into JSX children spread typing. |
| tests/cases/compiler/subtypeReductionWithAnyFunctionType.ts | New regression test for union subtype reduction involving anyFunctionType, ensuring real function types aren’t incorrectly reduced away. |
| tests/baselines/reference/subtypeReductionWithAnyFunctionType.types | Type baseline validating inferred types (notably the any parameter) for the new subtype reduction test. |
| tests/baselines/reference/subtypeReductionWithAnyFunctionType.symbols | Symbols baseline for the new subtype reduction test. |
| tests/baselines/reference/subtypeReductionWithAnyFunctionType.errors.txt | Error baseline asserting the expected TS7006 implicit-any diagnostic. |
| tests/cases/compiler/jsxFunctionTypeChildren.tsx | New regression test ensuring JSX children function typing behaves like the equivalent non-JSX call in a generic props scenario. |
| tests/baselines/reference/jsxFunctionTypeChildren.types | Type baseline for the JSX children function typing test. |
| tests/baselines/reference/jsxFunctionTypeChildren.symbols | Symbols baseline for the JSX children function typing test. |
| tests/cases/compiler/contextuallyTypedJsxChildren2.tsx | New regression test for context-sensitive JSX children discrimination with generic signatures (children-body vs non-children prop). |
| tests/baselines/reference/contextuallyTypedJsxChildren2.types | Type baseline validating correct inference (e.g. selected: number) for the JSX discrimination test. |
| tests/baselines/reference/contextuallyTypedJsxChildren2.symbols | Symbols baseline for the JSX discrimination test. |
|
Hey @DanielRosenwasser, it looks like the DT test run failed. Please check the log for more details. |
|
@typescript-bot run dt |
|
@DanielRosenwasser Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
|
Hey @jakebailey, it looks like the DT test run failed. Please check the log for more details. |
|
@DanielRosenwasser Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@DanielRosenwasser Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Ports two fixes from typescript-go:
anyFunctionTypea subtype of all function types typescript-go#1149 — MakeanyFunctionTypea subtype of all function typesanyFunctionTypesubtype relationIn
signaturesRelatedTo,anyFunctionTypewas treated symmetrically—both as source and target it returnedTernary.True. This caused incorrect subtype reduction: when a union includedanyFunctionTypealongside a real function type, the real type could be reduced away instead of the wildcard.Now
anyFunctionTypeis a proper subtype (source → True) but not a supertype (target → False). This fixes inference in patterns like:JSX children
NonInferrableTypepropagationWhen building the JSX attributes spread type for children,
getPropagatingFlagsOfTypes(childrenTypes)was not included in theobjectFlagspassed togetSpreadType. This meant theNonInferrableTypeflag fromanyFunctionTypechildren wasn't propagated, breaking context-sensitive discrimination for generic JSX component signatures.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.