Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve contextual types inferred from return types#61913

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ahejlsberg wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromimprove-return-context

Conversation

ahejlsberg
Copy link
Member

Implements the experiment discussedhere.

@CopilotCopilotAI review requested due to automatic review settingsJune 22, 2025 20:10
@typescript-bottypescript-bot added Author: Team For Uncommitted BugPR for untriaged, rejected, closed or missing bug labelsJun 22, 2025
Copy link

@CopilotCopilotAI 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 improves contextual type inference by introducing a new inference priority for mapping return types.

  • Added a new enum member ReturnMapper and updated the MaxValue and combination mask in InferencePriority.
  • Modified the type-checker to exclude any/unknown types when using the ReturnMapper inference and passed the new flag into the inferTypes function.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

FileDescription
src/compiler/types.tsAdded ReturnMapper to the InferencePriority enum and updated related bit masks.
src/compiler/checker.tsUpdated inference filtering to exclude any/unknown types and passed the ReturnMapper flag to inferTypes.
Comments suppressed due to low confidence (1)

@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 themon our wiki's API Breaking Changes page.

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

@ahejlsberg
Copy link
MemberAuthor

@typescript-bot test it

typescript-bot reacted with thumbs up emoji

@typescript-bot
Copy link
Collaborator

typescript-bot commentedJun 22, 2025
edited
Loading

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

CommandStatusResults
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@ahejlsberg, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the user tests with tsc comparingmain andrefs/pull/61913/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3434~~~p=1.000 n=6
Symbols62,37062,370~~~p=1.000 n=6
Types50,38650,386~~~p=1.000 n=6
Memory used194,094k (± 0.95%)193,548k (± 0.77%)~192,815k196,567kp=0.378 n=6
Parse Time1.31s (± 0.31%)1.30s (± 0.75%)~1.29s1.31sp=0.213 n=6
Bind Time0.73s0.73s~~~p=1.000 n=6
Check Time9.69s (± 0.29%)9.66s (± 0.22%)~9.63s9.69sp=0.077 n=6
Emit Time2.74s (± 0.93%)2.73s (± 1.40%)~2.67s2.77sp=1.000 n=6
Total Time14.46s (± 0.17%)14.42s (± 0.33%)~14.37s14.49sp=0.169 n=6
angular-1 - node (v18.15.0, x64)
Errors5656~~~p=1.000 n=6
Symbols948,750948,576-174 (- 0.02%)~~p=0.001 n=6
Types410,846410,804-42 (- 0.01%)~~p=0.001 n=6
Memory used1,224,589k (± 0.01%)1,224,440k (± 0.00%)-149k (- 0.01%)1,224,395k1,224,531kp=0.008 n=6
Parse Time6.62s (± 0.50%)6.64s (± 0.98%)~6.55s6.70sp=0.377 n=6
Bind Time1.89s (± 0.93%)1.89s (± 0.33%)~1.88s1.90sp=1.000 n=6
Check Time31.83s (± 0.14%)31.79s (± 0.27%)~31.65s31.88sp=0.470 n=6
Emit Time14.87s (± 0.57%)14.90s (± 0.42%)~14.84s14.99sp=0.520 n=6
Total Time55.20s (± 0.12%)55.22s (± 0.21%)~55.02s55.33sp=0.575 n=6
mui-docs - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,561,6582,561,485-173 (- 0.01%)~~p=0.001 n=6
Types892,631892,606-25 (- 0.00%)~~p=0.001 n=6
Memory used2,836,579k (± 0.00%)2,836,448k (± 0.00%)-130k (- 0.00%)2,836,398k2,836,529kp=0.013 n=6
Parse Time9.20s (± 0.50%)9.18s (± 0.25%)~9.14s9.20sp=0.571 n=6
Bind Time2.30s (± 0.22%)2.31s (± 0.33%)~2.30s2.32sp=0.247 n=6
Check Time83.62s (± 0.32%)83.67s (± 0.64%)~82.96s84.42sp=0.873 n=6
Emit Time0.30s (± 1.37%)0.30s (± 1.37%)~0.29s0.30sp=1.000 n=6
Total Time95.41s (± 0.29%)95.45s (± 0.58%)~94.73s96.21sp=0.810 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,227,1261,227,160+34 (+ 0.00%)~~p=0.001 n=6
Types267,408267,426+18 (+ 0.01%)~~p=0.001 n=6
Memory used2,362,056k (± 0.02%)2,422,890k (± 6.15%)~2,361,445k2,727,187kp=0.689 n=6
Parse Time5.20s (± 0.72%)5.20s (± 1.00%)~5.10s5.25sp=0.747 n=6
Bind Time1.80s (± 0.29%)1.80s (± 0.42%)~1.79s1.81sp=0.784 n=6
Check Time35.12s (± 0.19%)35.05s (± 0.44%)~34.76s35.19sp=0.377 n=6
Emit Time3.03s (± 4.41%)2.96s (± 1.02%)~2.93s3.02sp=0.298 n=6
Total Time45.16s (± 0.35%)45.03s (± 0.30%)~44.82s45.17sp=0.230 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,227,1261,227,160+34 (+ 0.00%)~~p=0.001 n=6
Types267,408267,426+18 (+ 0.01%)~~p=0.001 n=6
Memory used2,700,732k (±13.34%)2,796,386k (±14.25%)~2,431,816k3,162,628kp=0.575 n=6
Parse Time6.85s (± 1.83%)6.86s (± 1.24%)~6.77s6.95sp=0.689 n=6
Bind Time2.20s (± 2.23%)2.20s (± 1.37%)~2.16s2.25sp=1.000 n=6
Check Time42.60s (± 1.09%)42.62s (± 0.59%)~42.40s42.94sp=0.630 n=6
Emit Time3.61s (± 3.93%)3.46s (± 1.38%)🟩-0.15s (- 4.06%)3.41s3.55sp=0.045 n=6
Total Time55.25s (± 0.98%)55.12s (± 0.55%)~54.83s55.46sp=0.810 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols262,474262,470-4 (- 0.00%)~~p=0.001 n=6
Types107,135107,127-8 (- 0.01%)~~p=0.001 n=6
Memory used441,755k (± 0.01%)441,712k (± 0.01%)~441,640k441,809kp=0.230 n=6
Parse Time3.51s (± 1.70%)3.55s (± 1.31%)~3.50s3.60sp=0.126 n=6
Bind Time1.31s (± 1.25%)1.32s (± 0.83%)~1.31s1.34sp=0.188 n=6
Check Time18.83s (± 0.45%)18.82s (± 0.23%)~18.77s18.88sp=1.000 n=6
Emit Time1.52s (± 0.77%)1.51s (± 0.91%)~1.50s1.54sp=0.564 n=6
Total Time25.17s (± 0.49%)25.20s (± 0.28%)~25.11s25.29sp=0.296 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors7171~~~p=1.000 n=6
Symbols225,327225,354+27 (+ 0.01%)~~p=0.001 n=6
Types94,28894,289+1 (+ 0.00%)~~p=0.001 n=6
Memory used371,169k (± 0.03%)371,112k (± 0.02%)~371,048k371,239kp=0.378 n=6
Parse Time2.90s (± 1.17%)2.88s (± 0.90%)~2.84s2.91sp=0.418 n=6
Bind Time1.60s (± 0.61%)1.61s (± 2.00%)~1.56s1.64sp=0.373 n=6
Check Time16.36s (± 0.28%)16.26s (± 0.31%)-0.10s (- 0.61%)16.20s16.35sp=0.020 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time20.86s (± 0.33%)20.75s (± 0.43%)~20.65s20.88sp=0.092 n=6
vscode - node (v18.15.0, x64)
Errors3333~~~p=1.000 n=6
Symbols3,478,6233,478,628+5 (+ 0.00%)~~p=0.001 n=6
Types1,170,0821,170,057-25 (- 0.00%)~~p=0.001 n=6
Memory used3,526,701k (± 0.01%)3,526,781k (± 0.01%)~3,526,343k3,527,039kp=0.378 n=6
Parse Time15.06s (± 0.59%)15.08s (± 0.53%)~14.98s15.16sp=0.629 n=6
Bind Time4.87s (± 0.53%)4.85s (± 0.38%)~4.83s4.88sp=0.223 n=6
Check Time98.25s (± 3.23%)96.25s (± 3.35%)~93.12s100.63sp=0.298 n=6
Emit Time30.39s (± 2.82%)30.37s (± 4.16%)~29.34s32.54sp=0.936 n=6
Total Time148.57s (± 2.63%)146.57s (± 2.88%)~142.59s151.35sp=0.470 n=6
webpack - node (v18.15.0, x64)
Errors22~~~p=1.000 n=6
Symbols320,000320,000~~~p=1.000 n=6
Types140,356140,355-1 (- 0.00%)~~p=0.001 n=6
Memory used474,123k (± 0.01%)474,190k (± 0.02%)~474,041k474,306kp=0.199 n=6
Parse Time4.33s (± 0.71%)4.33s (± 0.79%)~4.28s4.37sp=0.936 n=6
Bind Time1.77s (± 1.21%)1.78s (± 1.17%)~1.75s1.80sp=0.871 n=6
Check Time20.67s (± 0.29%)20.66s (± 0.55%)~20.57s20.85sp=0.686 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time26.76s (± 0.26%)26.77s (± 0.36%)~26.68s26.93sp=1.000 n=6
xstate-main - node (v18.15.0, x64)
Errors3030~~~p=1.000 n=6
Symbols667,374667,148-226 (- 0.03%)~~p=0.001 n=6
Types198,751198,664-87 (- 0.04%)~~p=0.001 n=6
Memory used570,150k (± 0.00%)570,009k (± 0.02%)~569,915k570,225kp=0.066 n=6
Parse Time5.54s (± 0.56%)5.51s (± 1.13%)~5.43s5.57sp=0.809 n=6
Bind Time1.65s (± 0.54%)1.66s (± 0.38%)~1.65s1.67sp=0.070 n=6
Check Time25.33s (± 0.28%)25.25s (± 1.43%)~24.52s25.49sp=0.520 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time32.51s (± 0.17%)32.42s (± 1.08%)~31.73s32.69sp=0.809 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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top 400 repos with tsc comparingmain andrefs/pull/61913/merge:

Something interesting changed - please have a look.

Details

github/docs

1 of 2 projects failed to build with the old tsc and were ignored

tsconfig.json

  • error TS2739: Type '{ productVideo: any; productVideoTranscript: any; hasGuidesPage: any; product: { href: any; title: any; }; whatsNewChangelog: any; changelogUrl: any; productCommunityExamples: any; ghesReleases: any; ... 6 more ...; shortTitle: any; }' is missing the following properties from type 'ProductLandingContextT': introPlainText, intro, beta_product

gvergnaud/ts-pattern

tests/tsconfig.json

@Andarist
Copy link
Contributor

This PR addresses a different situation, but its generic title reminded me of#58910 ;p

@@ -7129,6 +7130,7 @@ export const enum InferenceFlags {
NoDefault = 1 << 0, // Infer silentNeverType for no inferences (otherwise anyType or unknownType)
AnyDefault = 1 << 1, // Infer anyType (in JS files) for no inferences (otherwise unknownType)
SkippedGenericFunction = 1 << 2, // A generic function was skipped during inference
NoUnknownInference = 1 << 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this stays unused

@Andarist
Copy link
Contributor

Minimal repro case for thegithub/docs problem:

typeMany<T>=T|readonlyT[];declarefunctionpick<Textendsobject,UextendskeyofT>(object:T,  ...props:Array<Many<U>>):Pick<T,U>;typeProductLandingContextT={title:string;intro:string;};constgetProductLandingContextFromRequest=async(req:any,):Promise<ProductLandingContextT>=>{constpage=req.context.page;consttitle=awaitpage.renderProp("title",req.context,{textOnly:true});return{    title,    ...pick(page,["intro"]),};};

@jakebailey
Copy link
Member

@typescript-bot pack this

typescript-bot reacted with thumbs up emoji

@typescript-bot
Copy link
Collaborator

typescript-bot commentedJun 23, 2025
edited
Loading

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

CommandStatusResults
pack this✅ Started✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commentedJun 23, 2025
edited
Loading

Hey@jakebailey, I've packed this intoan installable tgz. You can install it for testing by referencing it in yourpackage.json like so:

{    "devDependencies": {        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/165448/artifacts?artifactName=tgz&fileId=BEE85749DC012DFE0439FCB8B8A57B4EE5CFE5CE56B343DD2C6737B725BE3D7C02&fileName=/typescript-5.9.0-insiders.20250623.tgz"    }}

and then runningnpm install.


There is also a playgroundfor this build and annpm module you can use via"typescript": "npm:@typescript-deploys/pr-build@5.9.0-pr-61913-11".;

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AndaristAndaristAndarist left review comments

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees

@ahejlsbergahejlsberg

Labels
Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@ahejlsberg@typescript-bot@Andarist@jakebailey

[8]ページ先頭

©2009-2025 Movatter.jp