Skip to content

Use tuple context based on apparent type of the contextual type uninstantiated by return mapper #62174

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 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Aug 1, 2025

fixes #62071

it's a somewhat cheap shot at this recent inference regression

@Copilot Copilot AI review requested due to automatic review settings August 1, 2025 22:04
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Aug 1, 2025
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 fixes a recent inference regression related to tuple typing by improving contextual typing for array literals when return type mapping is involved. The change ensures that array literals receive proper tuple context even when the contextual type is instantiated by a return mapper.

Key changes:

  • Introduces a new SkipReturnMapper context flag to control when return mapper instantiation is applied
  • Modifies array literal checking to consider tuple context from both the standard contextual type and the contextual type without return mapper instantiation
  • Adds comprehensive test cases demonstrating the fix for both built-in and custom Promise implementations

Reviewed Changes

Copilot reviewed 6 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 new SkipReturnMapper context flag enum value
src/compiler/checker.ts Implements the fix by modifying contextual type resolution and array literal checking logic
tests/cases/compiler/returnTypeContextualTupleTyping1.ts Adds regression test cases for the tuple typing fix
tests/baselines/reference/returnTypeContextualTupleTyping1.types Expected type output baseline for the new test
tests/baselines/reference/returnTypeContextualTupleTyping1.symbols Expected symbol output baseline for the new test
tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types Updated baseline showing improved tuple inference behavior
Comments suppressed due to low confidence (2)

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 1, 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 @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey
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 194,830k (± 0.96%) 194,105k (± 0.94%) ~ 192,894k 196,518k p=0.128 n=6
Parse Time 1.31s 1.30s (± 0.75%) ~ 1.29s 1.31s p=0.073 n=6
Bind Time 0.73s 0.73s ~ ~ ~ p=1.000 n=6
Check Time 9.76s (± 0.28%) 9.76s (± 0.39%) ~ 9.70s 9.80s p=0.936 n=6
Emit Time 2.73s (± 0.68%) 2.73s (± 0.92%) ~ 2.71s 2.77s p=1.000 n=6
Total Time 14.52s (± 0.25%) 14.52s (± 0.28%) ~ 14.48s 14.58s p=0.936 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,885 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,226,397k (± 0.01%) 1,226,390k (± 0.00%) ~ 1,226,360k 1,226,483k p=0.689 n=6
Parse Time 6.48s (± 0.18%) 6.50s (± 0.29%) ~ 6.47s 6.52s p=0.250 n=6
Bind Time 1.87s 1.87s (± 0.22%) ~ 1.87s 1.88s p=0.405 n=6
Check Time 32.09s (± 0.30%) 32.15s (± 0.15%) ~ 32.11s 32.24s p=0.296 n=6
Emit Time 14.75s (± 0.71%) 14.76s (± 0.20%) ~ 14.71s 14.79s p=0.746 n=6
Total Time 55.19s (± 0.34%) 55.28s (± 0.14%) ~ 55.22s 55.43s p=0.470 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,543,160 2,543,160 ~ ~ ~ p=1.000 n=6
Types 900,384 900,387 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,829,541k (± 0.01%) 2,829,477k (± 0.01%) ~ 2,829,284k 2,829,730k p=0.521 n=6
Parse Time 8.75s (± 0.27%) 8.77s (± 0.17%) ~ 8.75s 8.79s p=0.324 n=6
Bind Time 2.25s (± 0.37%) 2.25s (± 0.91%) ~ 2.22s 2.28s p=0.933 n=6
Check Time 85.52s (± 0.32%) 85.80s (± 0.34%) ~ 85.35s 86.13s p=0.065 n=6
Emit Time 0.96s (±104.98%) 1.33s (±84.81%) ~ 0.30s 2.42s p=0.935 n=6
Total Time 97.49s (± 1.03%) 98.15s (± 1.24%) ~ 96.68s 99.57s p=0.173 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,066 1,227,080 +14 (+ 0.00%) ~ ~ p=0.001 n=6
Types 267,480 267,487 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,424,158k (± 6.16%) 2,424,446k (± 6.16%) ~ 2,363,085k 2,729,683k p=0.689 n=6
Parse Time 5.19s (± 0.91%) 5.21s (± 0.64%) ~ 5.17s 5.27s p=0.332 n=6
Bind Time 1.78s (± 1.09%) 1.78s (± 0.83%) ~ 1.76s 1.80s p=0.684 n=6
Check Time 35.31s (± 0.39%) 35.47s (± 0.64%) ~ 35.06s 35.68s p=0.065 n=6
Emit Time 2.99s (± 1.15%) 2.98s (± 1.00%) ~ 2.93s 3.01s p=0.747 n=6
Total Time 45.28s (± 0.35%) 45.45s (± 0.45%) +0.16s (+ 0.36%) 45.08s 45.64s p=0.045 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,066 1,227,080 +14 (+ 0.00%) ~ ~ p=0.001 n=6
Types 267,480 267,487 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,919,704k (±12.89%) 2,919,709k (±12.89%) ~ 2,433,022k 3,163,510k p=0.936 n=6
Parse Time 8.46s (± 1.03%) 8.47s (± 1.03%) ~ 8.33s 8.54s p=0.575 n=6
Bind Time 2.68s (± 2.12%) 2.70s (± 2.26%) ~ 2.61s 2.78s p=0.572 n=6
Check Time 53.16s (± 0.29%) 53.24s (± 0.70%) ~ 52.68s 53.67s p=0.575 n=6
Emit Time 4.50s (± 1.09%) 4.46s (± 2.95%) ~ 4.28s 4.68s p=0.471 n=6
Total Time 68.79s (± 0.19%) 68.88s (± 0.64%) ~ 68.13s 69.42s p=0.298 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 262,555 262,558 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Types 107,165 107,168 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 441,963k (± 0.01%) 442,039k (± 0.02%) ~ 441,894k 442,152k p=0.066 n=6
Parse Time 3.53s (± 0.99%) 3.54s (± 0.89%) ~ 3.50s 3.59s p=0.520 n=6
Bind Time 1.32s (± 0.91%) 1.32s (± 0.80%) ~ 1.30s 1.33s p=0.282 n=6
Check Time 18.97s (± 0.44%) 18.97s (± 0.27%) ~ 18.90s 19.03s p=0.514 n=6
Emit Time 1.53s (± 1.01%) 1.53s (± 1.22%) ~ 1.51s 1.56s p=0.681 n=6
Total Time 25.35s (± 0.30%) 25.37s (± 0.31%) ~ 25.27s 25.45s p=0.747 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,280k (± 0.06%) 371,194k (± 0.02%) ~ 371,143k 371,304k p=0.810 n=6
Parse Time 2.90s (± 0.75%) 2.89s (± 1.26%) ~ 2.84s 2.93s p=1.000 n=6
Bind Time 1.60s (± 1.88%) 1.60s (± 1.71%) ~ 1.57s 1.64s p=1.000 n=6
Check Time 16.41s (± 0.38%) 16.45s (± 0.27%) ~ 16.38s 16.50s p=0.199 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.90s (± 0.32%) 20.94s (± 0.26%) ~ 20.86s 21.00s p=0.295 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,560,246 3,560,373 +127 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,200,285 1,200,349 +64 (+ 0.01%) ~ ~ p=0.001 n=6
Memory used 3,604,358k (± 0.01%) 3,604,866k (± 0.04%) ~ 3,603,716k 3,607,353k p=0.575 n=6
Parse Time 15.28s (± 0.55%) 15.27s (± 0.48%) ~ 15.22s 15.42s p=0.627 n=6
Bind Time 4.92s (± 0.65%) 4.91s (± 0.64%) ~ 4.86s 4.93s p=0.560 n=6
Check Time 100.43s (± 1.65%) 101.35s (± 1.67%) ~ 98.59s 102.88s p=0.378 n=6
Emit Time 34.13s (±24.68%) 34.85s (±12.76%) ~ 30.86s 41.55s p=0.093 n=6
Total Time 154.76s (± 4.99%) 156.38s (± 2.98%) ~ 151.16s 164.19s p=0.173 n=6
webpack - node (v18.15.0, x64)
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 321,136 321,142 +6 (+ 0.00%) ~ ~ p=0.001 n=6
Types 140,173 140,174 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 477,390k (± 0.02%) 477,427k (± 0.02%) ~ 477,317k 477,545k p=0.378 n=6
Parse Time 4.30s (± 0.57%) 4.30s (± 0.27%) ~ 4.29s 4.32s p=0.740 n=6
Bind Time 1.80s (± 0.91%) 1.79s (± 0.76%) ~ 1.77s 1.81s p=0.060 n=6
Check Time 20.58s (± 0.13%) 20.62s (± 0.25%) ~ 20.58s 20.72s p=0.124 n=6
Emit Time 0.00s (±244.70%) 0.00s (±244.70%) ~ 0.00s 0.01s p=1.000 n=6
Total Time 26.69s (± 0.15%) 26.70s (± 0.17%) ~ 26.66s 26.79s p=0.872 n=6
xstate-main - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 663,079 663,132 +53 (+ 0.01%) ~ ~ p=0.001 n=6
Types 197,935 197,938 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 569,968k (± 0.02%) 570,133k (± 0.02%) +165k (+ 0.03%) 569,887k 570,250k p=0.037 n=6
Parse Time 4.28s (± 1.43%) 4.27s (± 1.14%) ~ 4.21s 4.35s p=0.572 n=6
Bind Time 1.32s (± 0.78%) 1.33s (± 0.77%) ~ 1.32s 1.35s p=0.134 n=6
Check Time 20.29s (± 1.57%) 19.97s (± 1.71%) ~ 19.80s 20.67s p=0.109 n=6
Emit Time 0.00s (±154.76%) 0.00s (±244.70%) ~ 0.00s 0.01s p=0.595 n=6
Total Time 25.89s (± 1.37%) 25.57s (± 1.36%) ~ 25.37s 26.28s p=0.173 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

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

Something interesting changed - please have a look.

Details

typeorm/typeorm

tsconfig.json

@Andarist
Copy link
Contributor Author

Andarist commented Aug 2, 2025

repro for the above break: TS playground,

EDIT:// and its smaller version: TS playground

@i-ayushh18

This comment was marked as spam.

@Andarist
Copy link
Contributor Author

Andarist commented Aug 2, 2025

I think the above cast in the repro case should just be allowed. I opened a new issue about this: #62177

@i-ayushh18
Copy link

🤖 AI Assistant: Task completed: PR #62174: Use tuple context based on apparent type of the contextual type uninstantiated by return ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Type inference regression on function calls not saved to variables, due to #61668
4 participants