Skip to content

Combine inferences from distributive conditional types #62093

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #62079

@Copilot Copilot AI review requested due to automatic review settings July 20, 2025 10:52
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jul 20, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jul 20, 2025
@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a fix for TypeScript issue #62079 by combining inferences from distributive conditional types. The change modifies the type inference system to properly handle parameters that use distributive conditional types, ensuring that inferences from multiple union member distributions are correctly combined.

  • Adds a new DistributiveConditional inference priority flag to track distributive conditional type inferences
  • Modifies inference priority logic to combine distributive conditional inferences with other priorities
  • Updates the conditional type inference process to mark distributive conditional types with the new priority

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/compiler/types.ts Adds DistributiveConditional inference priority flag and includes it in combination logic
src/compiler/checker.ts Implements distributive conditional inference tracking and priority combination logic
tests/cases/compiler/genericFunctionParametersConditionalType1.ts Test case demonstrating the fix for distributive conditional type parameter inference
tests/baselines/reference/genericFunctionParametersConditionalType1.types Expected type output showing proper union distribution in parameter types
tests/baselines/reference/genericFunctionParametersConditionalType1.symbols Expected symbol resolution output for the test case
Comments suppressed due to low confidence (1)

@@ -26784,13 +26784,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (candidate === blockedStringType) {
return;
}
if (inference.priority === undefined || priority < inference.priority) {
const combinedPriority = priority | (inference.individualPriority || InferencePriority.None);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite like how this turned out - I probably should move this thing to a separate InferenceInfo property (similar to topLevel) instead of shoving it into .priority.

That said, those changes would be cosmetic and wouldn't really change the idea behind this fix. In the meantime, I'd love to see what user/top tests have to say about this (cc @jakebailey )

@RyanCavanaugh
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 21, 2025

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started 👀 Results
user test this ✅ Started 👀 Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @RyanCavanaugh, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh Here are the results of running the user tests with tsc comparing main and refs/pull/62093/merge:

Something interesting changed - please have a look.

Details

effect

packages/effect/benchmark/tsconfig.json

tsconfig.json

tsconfig.build.json

packages/typeclass/dtslint/tsconfig.json

packages/platform/dtslint/tsconfig.json

packages/effect/dtslint/tsconfig.json

webpack

tsconfig.types.test.json

tsconfig.types.json

tsconfig.json

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,370 62,370 ~ ~ ~ p=1.000 n=6
Types 50,386 50,386 ~ ~ ~ p=1.000 n=6
Memory used 193,573k (± 0.76%) 194,753k (± 1.04%) ~ 192,901k 196,743k p=0.575 n=6
Parse Time 1.30s (± 0.64%) 1.30s (± 0.79%) ~ 1.29s 1.31s p=0.923 n=6
Bind Time 0.73s 0.73s ~ ~ ~ p=1.000 n=6
Check Time 9.75s (± 0.40%) 9.74s (± 0.22%) ~ 9.71s 9.77s p=0.260 n=6
Emit Time 2.74s (± 0.78%) 2.75s (± 0.69%) ~ 2.73s 2.78s p=0.511 n=6
Total Time 14.52s (± 0.30%) 14.52s (± 0.13%) ~ 14.50s 14.54s p=0.513 n=6
angular-1 - node (v18.15.0, x64)
Errors 56 56 ~ ~ ~ p=1.000 n=6
Symbols 948,914 948,914 ~ ~ ~ p=1.000 n=6
Types 410,884 410,884 ~ ~ ~ p=1.000 n=6
Memory used 1,226,389k (± 0.00%) 1,226,395k (± 0.01%) ~ 1,226,322k 1,226,495k p=0.936 n=6
Parse Time 6.53s (± 1.02%) 6.52s (± 0.85%) ~ 6.46s 6.62s p=1.000 n=6
Bind Time 1.87s (± 0.44%) 1.87s ~ ~ ~ p=0.290 n=6
Check Time 32.00s (± 0.27%) 31.97s (± 0.31%) ~ 31.88s 32.10s p=0.748 n=6
Emit Time 14.86s (± 0.97%) 14.85s (± 0.59%) ~ 14.74s 14.94s p=0.688 n=6
Total Time 55.26s (± 0.30%) 55.21s (± 0.22%) ~ 55.02s 55.36s p=0.423 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,542,899 2,542,993 +94 (+ 0.00%) ~ ~ p=0.001 n=6
Types 900,428 900,433 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,829,362k (± 0.00%) 2,829,402k (± 0.01%) ~ 2,829,202k 2,829,600k p=0.688 n=6
Parse Time 8.76s (± 0.29%) 8.75s (± 0.22%) ~ 8.72s 8.77s p=0.683 n=6
Bind Time 2.26s (± 0.23%) 2.24s (± 0.36%) -0.01s (- 0.59%) 2.23s 2.25s p=0.014 n=6
Check Time 85.74s (± 0.31%) 85.56s (± 0.49%) ~ 84.98s 86.20s p=0.378 n=6
Emit Time 0.59s (±119.68%) 1.01s (±95.34%) ~ 0.30s 2.24s p=0.184 n=6
Total Time 97.35s (± 0.86%) 97.56s (± 0.75%) ~ 96.64s 98.57s p=0.575 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,048 1,227,076 +28 (+ 0.00%) ~ ~ p=0.001 n=6
Types 267,470 267,475 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,363,435k (± 0.01%) 2,363,612k (± 0.02%) ~ 2,363,060k 2,364,027k p=0.378 n=6
Parse Time 5.21s (± 1.05%) 5.21s (± 1.13%) ~ 5.14s 5.30s p=0.872 n=6
Bind Time 1.80s (± 0.84%) 1.79s (± 1.62%) ~ 1.76s 1.83s p=0.684 n=6
Check Time 35.34s (± 0.46%) 35.43s (± 0.45%) ~ 35.23s 35.68s p=0.298 n=6
Emit Time 2.98s (± 1.32%) 2.97s (± 0.88%) ~ 2.93s 3.00s p=0.630 n=6
Total Time 45.34s (± 0.37%) 45.41s (± 0.40%) ~ 45.21s 45.71s p=0.575 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,048 1,227,076 +28 (+ 0.00%) ~ ~ p=0.001 n=6
Types 267,470 267,475 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,039,849k (± 9.77%) 3,161,978k (± 0.02%) ~ 3,161,210k 3,162,728k p=0.093 n=6
Parse Time 8.50s (± 1.20%) 8.55s (± 0.46%) ~ 8.51s 8.61s p=0.575 n=6
Bind Time 2.66s (± 1.80%) 2.64s (± 0.95%) ~ 2.61s 2.67s p=0.689 n=6
Check Time 53.22s (± 0.48%) 53.26s (± 0.23%) ~ 53.10s 53.45s p=0.936 n=6
Emit Time 4.46s (± 2.87%) 4.34s (± 2.32%) ~ 4.21s 4.45s p=0.090 n=6
Total Time 68.83s (± 0.48%) 68.79s (± 0.21%) ~ 68.66s 69.05s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 262,548 262,554 +6 (+ 0.00%) ~ ~ p=0.001 n=6
Types 107,156 107,161 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 441,929k (± 0.01%) 441,933k (± 0.01%) ~ 441,855k 442,020k p=0.936 n=6
Parse Time 3.56s (± 0.75%) 3.52s (± 0.61%) -0.04s (- 1.22%) 3.49s 3.55s p=0.024 n=6
Bind Time 1.32s (± 1.07%) 1.32s (± 0.89%) ~ 1.30s 1.33s p=0.934 n=6
Check Time 18.96s (± 0.39%) 18.94s (± 0.46%) ~ 18.86s 19.10s p=0.328 n=6
Emit Time 1.52s (± 0.68%) 1.53s (± 1.36%) ~ 1.49s 1.55s p=0.677 n=6
Total Time 25.36s (± 0.33%) 25.30s (± 0.30%) ~ 25.25s 25.44s p=0.170 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 71 71 ~ ~ ~ p=1.000 n=6
Symbols 225,367 225,367 ~ ~ ~ p=1.000 n=6
Types 94,290 94,290 ~ ~ ~ p=1.000 n=6
Memory used 371,155k (± 0.03%) 371,137k (± 0.02%) ~ 371,062k 371,229k p=1.000 n=6
Parse Time 2.87s (± 0.72%) 2.89s (± 0.99%) ~ 2.84s 2.92s p=0.257 n=6
Bind Time 1.59s (± 1.45%) 1.61s (± 0.94%) ~ 1.59s 1.63s p=0.243 n=6
Check Time 16.45s (± 0.27%) 16.45s (± 0.38%) ~ 16.36s 16.51s p=0.936 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.92s (± 0.30%) 20.95s (± 0.36%) ~ 20.85s 21.02s p=0.423 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,524,145 3,524,145 ~ ~ ~ p=1.000 n=6
Types 1,189,792 1,189,792 ~ ~ ~ p=1.000 n=6
Memory used 3,573,696k (± 0.00%) 3,573,744k (± 0.00%) ~ 3,573,612k 3,574,010k p=0.936 n=6
Parse Time 15.09s (± 0.25%) 15.31s (± 3.24%) ~ 15.03s 16.31s p=0.518 n=6
Bind Time 4.89s (± 0.56%) 4.93s (± 0.70%) ~ 4.89s 4.97s p=0.063 n=6
Check Time 101.49s (± 2.87%) 99.85s (± 0.91%) ~ 99.03s 101.54s p=0.298 n=6
Emit Time 31.45s (± 6.16%) 30.51s (± 0.72%) ~ 30.17s 30.82s p=0.575 n=6
Total Time 152.91s (± 1.99%) 150.60s (± 0.79%) ~ 149.19s 152.16s p=0.173 n=6
webpack - node (v18.15.0, x64)
Errors 2 7 🔻+5 (+250.00%) ~ ~ p=0.001 n=6
Symbols 320,541 330,861 +10,320 (+ 3.22%) ~ ~ p=0.001 n=6
Types 140,016 146,362 🔻+6,346 (+ 4.53%) ~ ~ p=0.001 n=6
Memory used 476,527k (± 0.04%) 483,704k (± 0.02%) +7,176k (+ 1.51%) 483,576k 483,847k p=0.005 n=6
Parse Time 4.31s (± 0.54%) 4.30s (± 0.74%) ~ 4.25s 4.35s p=0.935 n=6
Bind Time 1.80s (± 0.97%) 1.79s (± 1.29%) ~ 1.75s 1.82s p=0.567 n=6
Check Time 20.60s (± 0.40%) 20.91s (± 0.45%) +0.31s (+ 1.49%) 20.83s 21.07s p=0.005 n=6
Emit Time 0.00s 0.00s (±154.76%) ~ 0.00s 0.01s p=0.174 n=6
Total Time 26.71s (± 0.33%) 27.00s (± 0.49%) +0.29s (+ 1.08%) 26.85s 27.21s p=0.006 n=6
xstate-main - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 662,663 662,663 ~ ~ ~ p=1.000 n=6
Types 197,635 197,637 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 569,834k (± 0.02%) 569,778k (± 0.02%) ~ 569,601k 569,883k p=0.810 n=6
Parse Time 4.27s (± 0.53%) 4.25s (± 0.51%) ~ 4.22s 4.28s p=0.366 n=6
Bind Time 1.32s (± 0.88%) 1.33s (± 0.88%) ~ 1.31s 1.34s p=0.357 n=6
Check Time 19.96s (± 1.38%) 20.08s (± 1.58%) ~ 19.79s 20.53s p=0.336 n=6
Emit Time 0.00s (±244.70%) 0.00s ~ ~ ~ p=0.405 n=6
Total Time 25.55s (± 1.10%) 25.66s (± 1.32%) ~ 25.33s 26.12s p=0.689 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh Here are the results of running the top 400 repos with tsc comparing main and refs/pull/62093/merge:

Something interesting changed - please have a look.

Details

TanStack/query

78 of 118 projects failed to build with the old tsc and were ignored

packages/vue-query/tsconfig.prod.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Unable to infer parameters for generic constructor/functions with a distributive conditional type
3 participants