Skip to content

Fix narrowing of generic this parameters - #64187

Open
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix-generic-this-narrowing
Open

Fix narrowing of generic this parameters#64187
Mateusz Burzyński (Andarist) wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix-generic-this-narrowing

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes #64186

Copilot AI balanced review requested due to automatic review settings September 7, 2026 08:18
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 7, 2026
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 7, 2026

Copilot AI 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.

🟢 Approval recommended

The focused checker change consistently matches parameter behavior and is covered by comprehensive regression baselines.

Pull request overview

Aligns control-flow narrowing of generic this parameters with ordinary parameters, fixing #64186.

Changes:

  • Applies narrowable constraint types to this references while preserving check modes.
  • Adds regression tests for direct, aliased, contextual, indexed, and inferential usage.
  • Adds diagnostic, type, and symbol baselines.
File summaries
File Description
tsc/internal/checker/checker.go Enables consistent narrowing for generic this.
tsc/testdata/tests/cases/compiler/controlFlowGenericThis.ts Tests core narrowing behavior.
tsc/testdata/tests/cases/compiler/controlFlowGenericThisContextual.ts Tests contextual and inferential behavior.
tsc/testdata/baselines/reference/compiler/controlFlowGenericThis.errors.txt Records expected diagnostics.
tsc/testdata/baselines/reference/compiler/controlFlowGenericThis.types Records inferred types.
tsc/testdata/baselines/reference/compiler/controlFlowGenericThis.symbols Records resolved symbols.
tsc/testdata/baselines/reference/compiler/controlFlowGenericThisContextual.types Records contextual inferred types.
tsc/testdata/baselines/reference/compiler/controlFlowGenericThisContextual.symbols Records contextual symbols.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@jakebailey

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-automation

typescript-automation Bot commented Sep 8, 2026

Copy link
Copy Markdown

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
perf test this faster ✅ Started 👀 Results

@typescript-automation

Copy link
Copy Markdown

Jake Bailey (@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 - native
Errors 41 41 ~ ~ ~ p=1.000 n=12
Symbols 115,480 115,480 ~ ~ ~ p=1.000 n=12
Types 96,945 96,945 ~ ~ ~ p=1.000 n=12
Memory Used 148,605k (± 0.65%) 148,909k (± 0.43%) ~ 147,039k 150,759k p=0.590 n=12
Memory Allocs 2,271,289 (± 0.00%) 2,271,319 (± 0.01%) ~ 2,271,089 2,271,679 p=0.932 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.051s (± 3.99%) 0.050s (± 2.89%) ~ 0.047s 0.054s p=0.762 n=12
Bind Time 0.016s (±10.77%) 0.015s (±13.36%) ~ 0.013s 0.021s p=0.180 n=12
Check Time 0.594s (± 1.16%) 0.590s (± 1.11%) ~ 0.580s 0.614s p=0.163 n=12
Emit Time 0.326s (± 1.72%) 0.328s (± 1.63%) ~ 0.310s 0.337s p=0.541 n=12
Total Time 0.994s (± 0.95%) 0.991s (± 1.01%) ~ 0.967s 1.027s p=0.385 n=12
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=12
Symbols 846,997 (± 0.07%) 847,374 (± 0.09%) ~ 845,039 849,084 p=0.410 n=12
Types 249,852 (± 0.00%) 249,851 (± 0.00%) ~ 249,849 249,854 p=0.779 n=12
Memory Used 793,767k (± 0.07%) 793,839k (± 0.06%) ~ 793,072k 795,601k p=0.671 n=12
Memory Allocs 12,956,705 (± 0.07%) 12,956,144 (± 0.04%) ~ 12,949,527 12,974,151 p=0.843 n=12
Config Time 0.020s (± 0.91%) 0.021s (± 5.50%) ~ 0.019s 0.024s p=0.456 n=12
Parse Time 0.340s (± 2.55%) 0.355s (± 3.92%) ~ 0.314s 0.392s p=0.075 n=12
Bind Time 0.076s (± 6.47%) 0.095s (±16.80%) 🔻+0.019s (+24.32%) 0.073s 0.138s p=0.007 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 1.949s (± 0.59%) 2.076s (± 3.52%) 🔻+0.126s (+ 6.47%) 1.929s 2.359s p=0.002 n=12
Total Time 2.404s (± 0.58%) 2.570s (± 3.59%) 🔻+0.166s (+ 6.89%) 2.382s 2.932s p=0.003 n=12
mui-docs - native
Errors 11,275 (± 0.04%) 11,279 (± 0.02%) ~ 11,269 11,281 p=0.167 n=12
Symbols 4,267,465 4,267,465 ~ ~ ~ p=1.000 n=12
Types 1,475,860 1,475,860 ~ ~ ~ p=1.000 n=12
Memory Used 4,670,834k (± 0.03%) 4,671,718k (± 0.04%) ~ 4,669,028k 4,678,797k p=0.799 n=12
Memory Allocs 42,721,268 (± 0.04%) 42,728,042 (± 0.05%) ~ 42,687,199 42,779,034 p=0.799 n=12
Config Time 0.019s 0.019s ~ ~ ~ p=1.000 n=12
Parse Time 0.678s (± 1.73%) 0.668s (± 2.24%) ~ 0.619s 0.692s p=0.385 n=12
Bind Time 0.002s (±13.40%) 0.002s (±13.40%) ~ 0.002s 0.003s p=1.000 n=12
Check Time 20.030s (± 0.60%) 20.129s (± 0.63%) ~ 19.842s 20.365s p=0.193 n=12
Emit Time 0.574s (±13.62%) 0.595s (±17.06%) ~ 0.514s 1.010s p=0.259 n=12
Total Time 22.231s (± 0.67%) 22.365s (± 0.75%) ~ 21.917s 22.695s p=0.219 n=12
strada-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,394,252 1,394,252 ~ ~ ~ p=1.000 n=12
Types 443,418 443,418 ~ ~ ~ p=1.000 n=12
Memory Used 1,643,523k (± 0.25%) 1,649,166k (± 0.22%) +5,643k (+ 0.34%) 1,639,569k 1,656,490k p=0.039 n=12
Memory Allocs 97,038,306 (± 0.04%) 97,069,537 (± 0.04%) ~ 96,971,021 97,160,171 p=0.160 n=12
Config Time 0.006s (±13.36%) 0.006s (± 5.47%) ~ 0.005s 0.006s p=0.503 n=12
Parse Time 0.236s (± 2.74%) 0.241s (± 2.39%) ~ 0.219s 0.252s p=0.224 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 2.163s (± 0.37%) 2.163s (± 0.41%) ~ 2.137s 2.188s p=0.810 n=12
Emit Time 0.325s (± 4.72%) 0.351s (± 3.16%) 🔻+0.026s (+ 8.11%) 0.318s 0.370s p=0.008 n=12
Total Time 29.690s (± 0.53%) 29.954s (± 0.52%) +0.264s (+ 0.89%) 29.504s 30.373s p=0.021 n=12
strada-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 337,531 337,531 ~ ~ ~ p=1.000 n=12
Types 198,830 198,830 ~ ~ ~ p=1.000 n=12
Memory Used 319,484k (± 0.05%) 319,494k (± 0.05%) ~ 318,929k 319,755k p=0.319 n=12
Memory Allocs 4,672,435 (± 0.01%) 4,672,896 (± 0.01%) ~ 4,671,185 4,674,443 p=0.143 n=12
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=12
Parse Time 0.093s (± 3.47%) 0.093s (± 5.67%) ~ 0.078s 0.107s p=0.876 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 0.871s (± 0.39%) 0.868s (± 0.54%) ~ 0.861s 0.889s p=0.096 n=12
Emit Time 0.111s (±13.55%) 0.108s (±12.87%) ~ 0.081s 0.145s p=0.681 n=12
Total Time 1.118s (± 0.92%) 1.117s (± 1.27%) ~ 1.094s 1.154s p=0.723 n=12
ts-pre-modules - native
Errors 87 87 ~ ~ ~ p=1.000 n=12
Symbols 305,179 305,179 ~ ~ ~ p=1.000 n=12
Types 181,876 181,876 ~ ~ ~ p=1.000 n=12
Memory Used 277,178k (± 0.02%) 277,214k (± 0.02%) ~ 277,079k 277,363k p=0.478 n=12
Memory Allocs 1,641,906 (± 0.02%) 1,641,820 (± 0.01%) ~ 1,641,488 1,642,206 p=0.713 n=12
Config Time 0.000s (±146.91%) 0.000s (±113.79%) ~ 0.000s 0.001s p=1.000 n=12
Parse Time 0.103s (± 3.74%) 0.097s (± 3.71%) 🟩-0.006s (- 5.76%) 0.087s 0.105s p=0.029 n=12
Bind Time 0.037s (± 9.62%) 0.041s (± 8.31%) ~ 0.034s 0.050s p=0.069 n=12
Check Time 0.831s (± 0.56%) 0.832s (± 0.70%) ~ 0.820s 0.845s p=0.721 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.985s (± 0.94%) 0.984s (± 0.82%) ~ 0.969s 1.007s p=0.944 n=12
vscode - native
Errors 349 349 ~ ~ ~ p=1.000 n=12
Symbols 8,463,646 8,463,646 ~ ~ ~ p=1.000 n=12
Types 2,898,728 2,898,728 ~ ~ ~ p=1.000 n=12
Memory Used 5,713,814k (± 0.02%) 5,713,051k (± 0.01%) ~ 5,710,544k 5,715,798k p=0.075 n=12
Memory Allocs 43,915,824 (± 0.02%) 43,907,516 (± 0.01%) ~ 43,898,967 43,928,628 p=0.128 n=12
Config Time 0.064s (± 0.42%) 0.064s (± 0.42%) ~ 0.063s 0.065s p=1.000 n=12
Parse Time 1.672s (± 2.31%) 1.704s (± 2.19%) ~ 1.544s 1.763s p=0.182 n=12
Bind Time 0.422s (±18.72%) 0.381s (±12.32%) 🟩-0.041s (- 9.77%) 0.357s 0.618s p=0.003 n=12
Check Time 10.297s (± 1.49%) 10.444s (± 1.11%) ~ 9.894s 10.536s p=0.235 n=12
Emit Time 3.784s (±11.78%) 3.402s (± 8.24%) ~ 3.202s 4.771s p=0.071 n=12
Total Time 16.338s (± 2.10%) 16.087s (± 1.15%) ~ 15.929s 17.007s p=0.524 n=12
webpack - native
Errors 560 560 ~ ~ ~ p=1.000 n=12
Symbols 929,346 929,346 ~ ~ ~ p=1.000 n=12
Types 426,678 426,678 ~ ~ ~ p=1.000 n=12
Memory Used 718,565k (± 0.02%) 718,548k (± 0.02%) ~ 718,327k 718,887k p=0.755 n=12
Memory Allocs 4,699,829 (± 0.01%) 4,700,180 (± 0.03%) ~ 4,698,231 4,706,814 p=0.755 n=12
Config Time 0.008s 0.008s ~ ~ ~ p=1.000 n=12
Parse Time 0.226s (± 3.52%) 0.228s (± 3.04%) ~ 0.207s 0.248s p=0.788 n=12
Bind Time 0.053s (±18.45%) 0.049s (±12.32%) ~ 0.044s 0.075s p=0.317 n=12
Check Time 1.241s (± 1.01%) 1.244s (± 0.76%) ~ 1.214s 1.257s p=0.966 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.555s (± 0.74%) 1.555s (± 0.58%) ~ 1.537s 1.580s p=0.899 n=12
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,022,532 1,022,532 ~ ~ ~ p=1.000 n=12
Types 376,962 376,962 ~ ~ ~ p=1.000 n=12
Memory Used 603,429k (± 0.02%) 603,461k (± 0.01%) ~ 603,340k 603,640k p=0.713 n=12
Memory Allocs 4,753,643 (± 0.02%) 4,753,670 (± 0.03%) ~ 4,749,060 4,756,513 p=0.713 n=12
Config Time 0.002s 0.002s ~ ~ ~ p=1.000 n=12
Parse Time 0.117s (± 3.26%) 0.115s (± 4.76%) ~ 0.106s 0.134s p=0.339 n=12
Bind Time 0.031s (±20.22%) 0.039s (±20.53%) ~ 0.026s 0.057s p=0.050 n=12
Check Time 0.860s (± 1.27%) 0.858s (± 0.55%) ~ 0.847s 0.871s p=1.000 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.018s (± 1.20%) 1.022s (± 0.90%) ~ 0.996s 1.041s p=0.619 n=12
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • mui-docs - native
  • strada-build-src - native
  • strada-compiler - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 12
Baseline baseline 12

Developer Information:

Download Benchmarks

@typescript-automation

Copy link
Copy Markdown

Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing main and refs/pull/64187/merge:

There were infrastructure failures potentially unrelated to your change:

  • 2 instances of "Package install failed"
  • 1 instance of "Git clone failed"

Otherwise...

Everything looks good!

@typescript-automation

Copy link
Copy Markdown

Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing main and refs/pull/64187/merge:

Everything looks good!

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Narrowing of generic this is inconsistent with variable narrowing

3 participants