Skip to content

Reject exports from global augmentations - #64162

Draft
Daniel Rosenwasser (DanielRosenwasser) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-augmentation-export
Draft

Reject exports from global augmentations#64162
Daniel Rosenwasser (DanielRosenwasser) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-augmentation-export

Conversation

Copilot AI commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

export { XYZ } incorrectly accepted bindings declared in a declare global augmentation.

Changes

  • Treat global-augmentation module blocks as non-local export sources.
  • Add regression coverage for:
declare global {
    var XYZ: number;
}

export { XYZ }; // TS2661

Copilot AI and others added 2 commits September 4, 2026 00:55
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with exporting from global augmentations Reject exports from global augmentations Sep 4, 2026
@jakebailey
Jake Bailey (jakebailey) requested a balanced review from Copilot September 4, 2026 17:42

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 fix has regression coverage and no unresolved issues.

Pull request overview

Rejects exports whose bindings originate from declare global augmentations, fixing #64152.

Changes:

  • Detect global-augmentation declarations during export validation.
  • Add regression coverage and compiler baselines for TS2661.
File summaries
File Description
tsc/testdata/tests/cases/compiler/exportSpecifierForAGlobalAugmentation.ts Adds the regression case.
tsc/testdata/baselines/reference/compiler/exportSpecifierForAGlobalAugmentation.types Records inferred types.
tsc/testdata/baselines/reference/compiler/exportSpecifierForAGlobalAugmentation.symbols Records symbol resolution.
tsc/testdata/baselines/reference/compiler/exportSpecifierForAGlobalAugmentation.js Records emitted output.
tsc/testdata/baselines/reference/compiler/exportSpecifierForAGlobalAugmentation.errors.txt Verifies the TS2661 diagnostic.
tsc/internal/checker/checker.go Rejects exports sourced from global augmentations.
Review details
  • Files reviewed: 6/6 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.

@DanielRosenwasser

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-automation

typescript-automation Bot commented Sep 5, 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 ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-automation

Copy link
Copy Markdown

Daniel Rosenwasser (@DanielRosenwasser) Here are the results of running the user tests with tsc comparing main and refs/pull/64162/merge:

There were infrastructure failures potentially unrelated to your change:

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

Otherwise...

Something interesting changed - please have a look.

Details

xterm.js

src/tsconfig-library-base.json

  • [NEW] error TS2661: Cannot export 'AllowSharedBuffer'. Only local declarations can be exported from a module.
  • [NEW] error TS2661: Cannot export 'Buffer'. Only local declarations can be exported from a module.
  • [NEW] error TS2661: Cannot export 'NonSharedBuffer'. Only local declarations can be exported from a module.
  • [NEW] error TS2661: Cannot export 'BufferEncoding'. Only local declarations can be exported from a module.

@typescript-automation

Copy link
Copy Markdown

Daniel Rosenwasser (@DanielRosenwasser)
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,013k (± 0.49%) 148,350k (± 0.58%) ~ 146,499k 150,733k p=0.630 n=12
Memory Allocs 2,271,134 (± 0.00%) 2,271,232 (± 0.00%) ~ 2,270,976 2,271,604 p=0.089 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.041s (± 4.67%) 0.041s (± 4.22%) ~ 0.036s 0.045s p=0.924 n=12
Bind Time 0.013s (±10.12%) 0.013s (±12.04%) ~ 0.010s 0.017s p=0.763 n=12
Check Time 0.499s (± 1.10%) 0.496s (± 0.98%) ~ 0.486s 0.506s p=0.399 n=12
Emit Time 0.274s (± 2.56%) 0.270s (± 1.57%) ~ 0.260s 0.287s p=0.399 n=12
Total Time 0.833s (± 1.31%) 0.826s (± 0.70%) ~ 0.813s 0.848s p=0.560 n=12
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=12
Symbols 846,839 (± 0.09%) 847,257 (± 0.05%) ~ 846,210 848,254 p=0.347 n=12
Types 249,852 (± 0.00%) 249,853 (± 0.00%) ~ 249,849 249,864 p=0.563 n=12
Memory Used 793,229k (± 0.06%) 793,223k (± 0.05%) ~ 792,034k 793,942k p=0.660 n=12
Memory Allocs 12,955,907 (± 0.05%) 12,957,281 (± 0.09%) ~ 12,948,457 13,009,231 p=0.514 n=12
Config Time 0.016s 0.016s ~ ~ ~ p=1.000 n=12
Parse Time 0.273s (± 1.79%) 0.271s (± 2.48%) ~ 0.253s 0.284s p=0.660 n=12
Bind Time 0.064s (±11.62%) 0.067s (±13.66%) ~ 0.057s 0.094s p=0.932 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 1.630s (± 1.12%) 1.641s (± 1.52%) ~ 1.599s 1.727s p=0.876 n=12
Total Time 2.001s (± 1.30%) 2.013s (± 1.54%) ~ 1.971s 2.119s p=0.522 n=12
mui-docs - native
Errors 11,275 (± 0.05%) 11,274 (± 0.06%) ~ 11,243 11,281 p=0.852 n=12
Symbols 4,165,469 4,165,469 ~ ~ ~ p=1.000 n=12
Types 1,592,109 1,592,109 ~ ~ ~ p=1.000 n=12
Memory Used 4,689,405k (± 0.03%) 4,688,146k (± 0.04%) ~ 4,683,757k 4,693,987k p=0.242 n=12
Memory Allocs 47,010,599 (± 0.04%) 47,011,095 (± 0.04%) ~ 46,957,795 47,067,081 p=0.932 n=12
Config Time 0.016s (± 1.98%) 0.016s (± 1.98%) ~ 0.015s 0.016s p=1.000 n=12
Parse Time 0.546s (± 1.71%) 0.546s (± 2.35%) ~ 0.503s 0.573s p=0.966 n=12
Bind Time 0.002s 0.002s (± 8.72%) ~ 0.002s 0.003s p=1.000 n=12
Check Time 17.303s (± 0.64%) 17.175s (± 0.33%) ~ 17.098s 17.366s p=0.068 n=12
Emit Time 0.442s (± 4.92%) 0.433s (± 0.38%) ~ 0.430s 0.438s p=0.593 n=12
Total Time 19.058s (± 0.66%) 18.898s (± 0.39%) ~ 18.773s 19.096s p=0.052 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,646,202k (± 0.26%) 1,647,292k (± 0.35%) ~ 1,632,283k 1,664,468k p=0.713 n=12
Memory Allocs 97,031,113 (± 0.03%) 97,058,514 (± 0.05%) ~ 96,960,855 97,195,879 p=0.514 n=12
Config Time 0.004s (±10.30%) 0.004s (±13.70%) ~ 0.003s 0.005s p=0.384 n=12
Parse Time 0.194s (± 2.27%) 0.196s (± 2.13%) ~ 0.184s 0.209s p=0.619 n=12
Bind Time 0.000s 0.000s (±217.90%) ~ 0.000s 0.003s p=1.000 n=12
Check Time 1.822s (± 0.41%) 1.803s (± 0.45%) -0.019s (- 1.03%) 1.781s 1.823s p=0.002 n=12
Emit Time 0.277s (± 6.59%) 0.279s (± 6.23%) ~ 0.243s 0.323s p=0.943 n=12
Total Time 24.835s (± 0.85%) 24.739s (± 0.66%) ~ 24.411s 25.246s p=0.524 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,417k (± 0.03%) 319,563k (± 0.02%) +146k (+ 0.05%) 319,427k 319,721k p=0.024 n=12
Memory Allocs 4,672,622 (± 0.01%) 4,673,075 (± 0.01%) ~ 4,671,871 4,674,616 p=0.143 n=12
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=12
Parse Time 0.115s (± 4.09%) 0.114s (± 4.59%) ~ 0.101s 0.128s p=0.722 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 1.051s (± 0.37%) 1.047s (± 0.56%) ~ 1.030s 1.063s p=0.212 n=12
Emit Time 0.127s (±10.69%) 0.143s (±10.64%) ~ 0.101s 0.171s p=0.110 n=12
Total Time 1.350s (± 0.70%) 1.358s (± 0.90%) ~ 1.318s 1.378s p=0.147 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,174k (± 0.02%) 277,136k (± 0.02%) ~ 277,020k 277,224k p=0.478 n=12
Memory Allocs 1,641,835 (± 0.01%) 1,641,809 (± 0.01%) ~ 1,641,420 1,642,276 p=0.630 n=12
Config Time 0.000s (±92.91%) 0.000s (±146.91%) ~ 0.000s 0.001s p=0.640 n=12
Parse Time 0.099s (± 4.99%) 0.100s (± 4.79%) ~ 0.088s 0.113s p=0.619 n=12
Bind Time 0.040s (±10.41%) 0.036s (± 7.69%) ~ 0.031s 0.046s p=0.145 n=12
Check Time 0.838s (± 0.43%) 0.837s (± 0.66%) ~ 0.824s 0.855s p=0.680 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.991s (± 0.83%) 0.988s (± 0.74%) ~ 0.972s 1.009s p=0.788 n=12
vscode - native
Errors 349 349 ~ ~ ~ p=1.000 n=12
Symbols 8,291,678 8,291,678 ~ ~ ~ p=1.000 n=12
Types 2,834,636 2,834,636 ~ ~ ~ p=1.000 n=12
Memory Used 5,611,675k (± 0.02%) 5,613,039k (± 0.02%) +1,364k (+ 0.02%) 5,611,309k 5,616,142k p=0.039 n=12
Memory Allocs 43,156,251 (± 0.01%) 43,162,556 (± 0.03%) ~ 43,150,800 43,216,255 p=0.347 n=12
Config Time 0.063s (± 0.51%) 0.064s (± 1.38%) ~ 0.063s 0.068s p=0.733 n=12
Parse Time 1.627s (± 3.80%) 1.668s (± 2.97%) ~ 1.531s 1.766s p=0.272 n=12
Bind Time 0.479s (±22.14%) 0.389s (±15.05%) ~ 0.349s 0.671s p=0.283 n=12
Check Time 9.873s (± 1.77%) 10.013s (± 1.30%) ~ 9.563s 10.230s p=0.203 n=12
Emit Time 3.994s (±13.60%) 3.549s (±10.77%) ~ 3.161s 5.020s p=0.291 n=12
Total Time 16.133s (± 2.60%) 15.776s (± 1.83%) ~ 15.439s 16.960s p=0.319 n=12
webpack - native
Errors 545 549 +4 (+ 0.73%) ~ ~ p=0.000 n=12
Symbols 918,784 918,784 ~ ~ ~ p=1.000 n=12
Types 421,470 421,470 ~ ~ ~ p=1.000 n=12
Memory Used 705,473k (± 0.02%) 705,437k (± 0.02%) ~ 705,140k 705,913k p=0.443 n=12
Memory Allocs 4,581,617 (± 0.02%) 4,581,899 (± 0.02%) ~ 4,580,882 4,585,570 p=0.242 n=12
Config Time 0.008s 0.008s ~ ~ ~ p=1.000 n=12
Parse Time 0.222s (± 2.76%) 0.226s (± 1.69%) ~ 0.213s 0.235s p=0.182 n=12
Bind Time 0.048s (±11.67%) 0.046s (± 5.44%) ~ 0.043s 0.055s p=0.721 n=12
Check Time 1.280s (± 0.47%) 1.285s (± 0.95%) ~ 1.254s 1.335s p=0.486 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.582s (± 0.51%) 1.589s (± 0.79%) ~ 1.564s 1.640s p=0.434 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,535k (± 0.01%) 603,504k (± 0.02%) ~ 603,240k 603,759k p=0.478 n=12
Memory Allocs 4,753,438 (± 0.05%) 4,753,895 (± 0.04%) ~ 4,750,242 4,760,619 p=0.590 n=12
Config Time 0.003s (± 8.64%) 0.003s (±10.34%) ~ 0.002s 0.003s p=1.000 n=12
Parse Time 0.145s (± 2.99%) 0.147s (± 3.06%) ~ 0.137s 0.157s p=0.679 n=12
Bind Time 0.046s (±15.71%) 0.043s (±18.74%) ~ 0.032s 0.067s p=0.830 n=12
Check Time 1.036s (± 0.53%) 1.045s (± 1.02%) ~ 1.026s 1.069s p=0.203 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.243s (± 0.99%) 1.249s (± 1.04%) ~ 1.222s 1.287s p=0.401 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

Hey Daniel Rosenwasser (@DanielRosenwasser), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-automation

Copy link
Copy Markdown

Daniel Rosenwasser (@DanielRosenwasser) Here are the results of running the top 400 repos with tsc comparing main and refs/pull/64162/merge:

Everything looks good!

@jakebailey

Copy link
Copy Markdown
Member

DT is not yet working, I suspect this will break a lot there

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

None yet

Development

Successfully merging this pull request may close these issues.

No error when exporting from global augmentations

4 participants