GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support resolving `@typescript/[lib]` in node modules by orta · Pull Request #45771 · microsoft/TypeScript

Conversation

@orta

@orta Orta Therox (orta) commented Sep 7, 2021 •
edited by DanielRosenwasser
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Note that #46046 updated this implementation with adding @typescript/lib-[x].


Closes #45518 as an alternative which leaves the responsibilities of configuring the environment to your package manager. Re #45688 #45685 and #44795

This answer to supporting your own versions of in-built libraries uses the node_modules resolution structure to let you define libraries. The path lookup looks like:

  • lib.dom.d.ts -> @typescript/dom
  • lib.dom.iterable.d.ts -> @typescript/dom/iterable
  • lib.es2015.symbol.wellknown.d.ts -> @typescript/es2015/symbol-wellknown

If you made a package which just sets up @typescript/es2015/symbol-wellknown.d.ts without @typescript/es2015/index.d.ts, then es2015 would still resolve to the TypeScript hosted version.

All JS dependency managers support this syntax:

{
  "devDependencies": {
    "@typescript/lib-dom": "npm:@types/web"
  }
}

This gives people the chance to make their own package with the .d.ts files in the right place and then set it up safely in their own project similar to @types. As we own @typescript/x on npm (and only have a few modules like @typescript/vfs, none of which clash) - then we don't need to worry about 'what happens if someone accidentally includes it twice' via the dependency tree.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

micheleb, sandersn, southpolesteve, kevinramharak, yoyo930021, nicojs, MattiasBuelens, reverofevil, andrewbranch, delucis, and 5 more reacted with heart emoji reverofevil and worstpractice reacted with rocket emoji
All reactions
  • ❤️ 15 reactions
  • 🚀 2 reactions
Orta Therox (orta) added 2 commits September 7, 2021 15:48
@orta
Support resolving @typescript/x for libs
6efc2f1
@orta
Baselines
2ec03f3
@typescript-bot TypeScript Bot (typescript-bot) assigned Orta Therox (orta) Sep 7, 2021
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 7, 2021
@orta Orta Therox (orta) mentioned this pull request Sep 8, 2021
Adds support for overwriting lib references via the TSConfig #45518
Closed
5 tasks
@orta
Tightens up the PR
daa99ce
@orta
Orta Therox (orta) requested review from Andrew Branch (andrewbranch) and Wesley Wigham (weswigham) September 14, 2021 14:56
@orta

Orta Therox (orta) commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) perf test
TypeScript Bot (@typescript-bot) pack this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Orta Therox (@orta), I've started to run the perf test suite on this PR at daa99ce. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at daa99ce. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey Orta Therox (@orta), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/110462/artifacts?artifactName=tgz&fileId=2DE81E5CC943F129DD37FCDD4A05363F2460D8444D5A74006585CA7254DA912A02&fileName=/typescript-4.5.0-insiders.20210914.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

Orta Therox (@orta)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..45771

Metric main 45771 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 351,531k (± 0.02%) 351,585k (± 0.02%) +54k (+ 0.02%) 351,465k 351,753k
Parse Time 1.90s (± 0.30%) 1.92s (± 0.56%) +0.02s (+ 1.00%) 1.90s 1.94s
Bind Time 0.85s (± 0.80%) 0.85s (± 1.09%) -0.00s (- 0.23%) 0.84s 0.88s
Check Time 5.43s (± 0.42%) 5.43s (± 0.37%) +0.00s (+ 0.00%) 5.39s 5.48s
Emit Time 5.81s (± 0.50%) 5.85s (± 0.51%) +0.03s (+ 0.53%) 5.79s 5.94s
Total Time 14.00s (± 0.27%) 14.04s (± 0.34%) +0.05s (+ 0.35%) 13.94s 14.19s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,538k (± 0.04%) 203,558k (± 0.02%) +19k (+ 0.01%) 203,416k 203,639k
Parse Time 0.78s (± 0.87%) 0.79s (± 0.94%) +0.01s (+ 0.64%) 0.77s 0.80s
Bind Time 0.52s (± 1.11%) 0.53s (± 1.44%) +0.00s (+ 0.57%) 0.51s 0.54s
Check Time 7.88s (± 0.61%) 7.88s (± 0.60%) -0.01s (- 0.08%) 7.76s 8.01s
Emit Time 2.45s (± 0.69%) 2.48s (± 1.15%) +0.03s (+ 1.27%) 2.43s 2.56s
Total Time 11.64s (± 0.53%) 11.67s (± 0.52%) +0.04s (+ 0.30%) 11.49s 11.83s
Monaco - node (v10.16.3, x64)
Memory used 340,597k (± 0.02%) 340,642k (± 0.03%) +44k (+ 0.01%) 340,364k 340,803k
Parse Time 1.44s (± 0.99%) 1.46s (± 0.61%) +0.02s (+ 1.04%) 1.44s 1.48s
Bind Time 0.75s (± 1.04%) 0.75s (± 0.82%) +0.00s (+ 0.00%) 0.74s 0.76s
Check Time 5.45s (± 0.48%) 5.46s (± 0.35%) +0.01s (+ 0.20%) 5.42s 5.50s
Emit Time 3.17s (± 0.87%) 3.16s (± 0.83%) -0.00s (- 0.09%) 3.11s 3.23s
Total Time 10.80s (± 0.44%) 10.82s (± 0.30%) +0.02s (+ 0.18%) 10.74s 10.88s
TFS - node (v10.16.3, x64)
Memory used 304,064k (± 0.02%) 304,081k (± 0.02%) +17k (+ 0.01%) 303,892k 304,208k
Parse Time 1.18s (± 0.34%) 1.19s (± 0.68%) +0.01s (+ 0.76%) 1.17s 1.20s
Bind Time 0.71s (± 1.05%) 0.72s (± 0.69%) +0.00s (+ 0.42%) 0.70s 0.72s
Check Time 4.95s (± 0.66%) 4.95s (± 0.57%) +0.00s (+ 0.06%) 4.88s 5.00s
Emit Time 3.31s (± 0.95%) 3.37s (± 1.73%) +0.06s (+ 1.84%) 3.28s 3.51s
Total Time 10.15s (± 0.51%) 10.22s (± 0.82%) +0.08s (+ 0.75%) 10.08s 10.42s
material-ui - node (v10.16.3, x64)
Memory used 468,283k (± 0.02%) 468,332k (± 0.01%) +49k (+ 0.01%) 468,231k 468,407k
Parse Time 1.73s (± 0.22%) 1.75s (± 0.47%) +0.02s (+ 1.28%) 1.73s 1.76s
Bind Time 0.67s (± 1.12%) 0.67s (± 0.97%) +0.00s (+ 0.15%) 0.65s 0.68s
Check Time 14.29s (± 0.32%) 14.34s (± 0.72%) +0.05s (+ 0.38%) 14.08s 14.59s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.68s (± 0.25%) 16.76s (± 0.58%) +0.07s (+ 0.43%) 16.52s 16.98s
Angular - node (v12.1.0, x64)
Memory used 329,505k (± 0.02%) 329,556k (± 0.03%) +51k (+ 0.02%) 329,424k 329,852k
Parse Time 1.87s (± 0.61%) 1.90s (± 0.34%) +0.03s (+ 1.60%) 1.89s 1.92s
Bind Time 0.84s (± 0.59%) 0.84s (± 0.79%) +0.00s (+ 0.48%) 0.83s 0.86s
Check Time 5.29s (± 0.55%) 5.28s (± 0.50%) -0.01s (- 0.17%) 5.22s 5.33s
Emit Time 6.10s (± 0.70%) 6.11s (± 0.98%) +0.01s (+ 0.20%) 6.02s 6.32s
Total Time 14.10s (± 0.40%) 14.13s (± 0.60%) +0.03s (+ 0.21%) 13.99s 14.40s
Compiler-Unions - node (v12.1.0, x64)
Memory used 191,055k (± 0.12%) 191,080k (± 0.07%) +25k (+ 0.01%) 190,554k 191,257k
Parse Time 0.78s (± 0.51%) 0.78s (± 0.97%) +0.01s (+ 0.77%) 0.77s 0.80s
Bind Time 0.53s (± 1.09%) 0.53s (± 0.89%) +0.00s (+ 0.57%) 0.52s 0.54s
Check Time 7.43s (± 0.56%) 7.44s (± 0.58%) +0.01s (+ 0.07%) 7.36s 7.56s
Emit Time 2.46s (± 0.51%) 2.47s (± 0.74%) +0.01s (+ 0.49%) 2.43s 2.51s
Total Time 11.20s (± 0.44%) 11.23s (± 0.48%) +0.03s (+ 0.23%) 11.10s 11.38s
Monaco - node (v12.1.0, x64)
Memory used 323,687k (± 0.08%) 323,766k (± 0.05%) +79k (+ 0.02%) 323,136k 323,949k
Parse Time 1.44s (± 0.78%) 1.44s (± 1.02%) +0.00s (+ 0.28%) 1.41s 1.47s
Bind Time 0.73s (± 1.18%) 0.73s (± 0.84%) -0.00s (- 0.14%) 0.72s 0.75s
Check Time 5.33s (± 0.60%) 5.32s (± 0.41%) -0.00s (- 0.04%) 5.29s 5.37s
Emit Time 3.22s (± 0.97%) 3.22s (± 0.53%) -0.00s (- 0.12%) 3.18s 3.25s
Total Time 10.72s (± 0.58%) 10.71s (± 0.30%) -0.00s (- 0.02%) 10.65s 10.81s
TFS - node (v12.1.0, x64)
Memory used 288,824k (± 0.03%) 288,819k (± 0.02%) -5k (- 0.00%) 288,661k 288,941k
Parse Time 1.21s (± 0.51%) 1.22s (± 0.77%) +0.01s (+ 0.50%) 1.20s 1.24s
Bind Time 0.70s (± 0.42%) 0.70s (± 1.71%) +0.00s (+ 0.43%) 0.68s 0.73s
Check Time 4.90s (± 0.56%) 4.90s (± 0.42%) -0.00s (- 0.06%) 4.86s 4.95s
Emit Time 3.39s (± 1.11%) 3.40s (± 0.55%) +0.01s (+ 0.27%) 3.36s 3.45s
Total Time 10.21s (± 0.52%) 10.23s (± 0.37%) +0.02s (+ 0.18%) 10.14s 10.31s
material-ui - node (v12.1.0, x64)
Memory used 447,022k (± 0.05%) 447,014k (± 0.07%) -8k (- 0.00%) 445,824k 447,300k
Parse Time 1.73s (± 0.67%) 1.75s (± 0.50%) +0.02s (+ 1.22%) 1.73s 1.76s
Bind Time 0.65s (± 0.89%) 0.65s (± 0.77%) -0.01s (- 1.23%) 0.63s 0.65s
Check Time 12.96s (± 1.00%) 13.06s (± 0.71%) +0.10s (+ 0.74%) 12.81s 13.23s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.34s (± 0.84%) 15.45s (± 0.65%) +0.11s (+ 0.71%) 15.19s 15.64s
Angular - node (v14.15.1, x64)
Memory used 328,057k (± 0.01%) 328,079k (± 0.01%) +21k (+ 0.01%) 328,034k 328,141k
Parse Time 1.90s (± 0.63%) 1.93s (± 0.60%) +0.02s (+ 1.26%) 1.91s 1.96s
Bind Time 0.88s (± 0.65%) 0.88s (± 0.66%) +0.00s (+ 0.34%) 0.87s 0.90s
Check Time 5.31s (± 0.55%) 5.34s (± 0.30%) +0.03s (+ 0.56%) 5.31s 5.39s
Emit Time 6.22s (± 0.46%) 6.21s (± 0.70%) -0.02s (- 0.29%) 6.13s 6.34s
Total Time 14.32s (± 0.27%) 14.36s (± 0.31%) +0.04s (+ 0.29%) 14.30s 14.51s
Compiler-Unions - node (v14.15.1, x64)
Memory used 191,905k (± 0.56%) 191,597k (± 0.60%) -308k (- 0.16%) 189,629k 192,945k
Parse Time 0.80s (± 0.62%) 0.81s (± 0.64%) +0.01s (+ 0.75%) 0.80s 0.83s
Bind Time 0.56s (± 1.00%) 0.56s (± 0.40%) +0.00s (+ 0.18%) 0.55s 0.56s
Check Time 7.55s (± 0.66%) 7.56s (± 0.54%) +0.01s (+ 0.11%) 7.49s 7.64s
Emit Time 2.44s (± 1.03%) 2.45s (± 0.67%) +0.01s (+ 0.45%) 2.42s 2.49s
Total Time 11.36s (± 0.56%) 11.39s (± 0.43%) +0.03s (+ 0.24%) 11.28s 11.51s
Monaco - node (v14.15.1, x64)
Memory used 322,563k (± 0.00%) 322,566k (± 0.00%) +3k (+ 0.00%) 322,543k 322,589k
Parse Time 1.49s (± 0.68%) 1.49s (± 0.86%) +0.01s (+ 0.40%) 1.47s 1.53s
Bind Time 0.75s (± 0.40%) 0.75s (± 0.69%) -0.00s (- 0.13%) 0.74s 0.76s
Check Time 5.26s (± 0.53%) 5.27s (± 0.55%) +0.01s (+ 0.13%) 5.21s 5.34s
Emit Time 3.24s (± 0.73%) 3.23s (± 0.77%) -0.00s (- 0.09%) 3.19s 3.29s
Total Time 10.73s (± 0.38%) 10.74s (± 0.40%) +0.01s (+ 0.13%) 10.65s 10.83s
TFS - node (v14.15.1, x64)
Memory used 287,738k (± 0.00%) 287,753k (± 0.01%) +15k (+ 0.01%) 287,720k 287,787k
Parse Time 1.23s (± 1.87%) 1.23s (± 1.79%) +0.00s (+ 0.08%) 1.20s 1.29s
Bind Time 0.74s (± 3.03%) 0.76s (± 4.64%) +0.02s (+ 3.13%) 0.72s 0.84s
Check Time 4.91s (± 0.38%) 4.90s (± 0.44%) -0.01s (- 0.31%) 4.85s 4.95s
Emit Time 3.48s (± 0.49%) 3.47s (± 0.58%) -0.02s (- 0.46%) 3.43s 3.52s
Total Time 10.36s (± 0.24%) 10.36s (± 0.55%) -0.00s (- 0.01%) 10.23s 10.47s
material-ui - node (v14.15.1, x64)
Memory used 445,503k (± 0.00%) 445,507k (± 0.00%) +4k (+ 0.00%) 445,487k 445,542k
Parse Time 1.77s (± 0.57%) 1.78s (± 0.37%) +0.01s (+ 0.85%) 1.76s 1.79s
Bind Time 0.69s (± 0.64%) 0.70s (± 0.68%) +0.01s (+ 0.72%) 0.69s 0.71s
Check Time 13.05s (± 0.56%) 13.08s (± 0.46%) +0.03s (+ 0.24%) 12.96s 13.19s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.51s (± 0.52%) 15.56s (± 0.39%) +0.05s (+ 0.32%) 15.43s 15.67s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory9 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 45771 10
Baseline main 10

Developer Information:

Download Benchmark

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta

Orta Therox (orta) commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

Actually trying this IRL is giving me unexpected results,

Code:
var localOverride = ts.resolveModuleName("@typescript/" + path, currentDirectory, { moduleResolution: ts.ModuleResolutionKind.NodeJs }, host);
console.log({ libFileName, localOverride, currentDirectory  })

Result:
{
  libFileName: 'lib.dom.d.ts',
  localOverride: {
    resolvedModule: undefined,
    failedLookupLocations: [
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom.ts',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom.tsx',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom.d.ts',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/index.ts',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/index.tsx',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/index.d.ts',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@types/typescript__dom/package.json',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@types/typescript__dom.d.ts',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@types/typescript__dom/index.d.ts',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom.ts',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom.tsx',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom.d.ts',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/index.ts',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/index.tsx',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/index.d.ts',
      '/Users/ortatherox/dev/typescript/node_modules/@types/typescript__dom/package.json',
      '/Users/ortatherox/dev/typescript/node_modules/@types/typescript__dom.d.ts',
      '/Users/ortatherox/dev/typescript/node_modules/@types/typescript__dom/index.d.ts',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/dev/node_modules/@typescript/dom.ts',
      '/Users/ortatherox/dev/node_modules/@typescript/dom.tsx',
      '/Users/ortatherox/dev/node_modules/@typescript/dom.d.ts',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/index.ts',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/index.tsx',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/index.d.ts',
      '/Users/ortatherox/dev/node_modules/@types/typescript__dom/package.json',
      '/Users/ortatherox/dev/node_modules/@types/typescript__dom.d.ts',
      '/Users/ortatherox/dev/node_modules/@types/typescript__dom/index.d.ts',
      '/Users/ortatherox/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/node_modules/@typescript/dom.ts',
      '/Users/ortatherox/node_modules/@typescript/dom.tsx',
      '/Users/ortatherox/node_modules/@typescript/dom.d.ts',
      '/Users/ortatherox/node_modules/@typescript/dom/index.ts',
      '/Users/ortatherox/node_modules/@typescript/dom/index.tsx',
      '/Users/ortatherox/node_modules/@typescript/dom/index.d.ts',
      '/Users/ortatherox/node_modules/@types/typescript__dom/package.json',
      '/Users/ortatherox/node_modules/@types/typescript__dom.d.ts',
      '/Users/ortatherox/node_modules/@types/typescript__dom/index.d.ts',
      '/Users/node_modules/@typescript/dom/package.json',
      '/Users/node_modules/@typescript/dom.ts',
      '/Users/node_modules/@typescript/dom.tsx',
      '/Users/node_modules/@typescript/dom.d.ts',
      '/Users/node_modules/@typescript/dom/index.ts',
      '/Users/node_modules/@typescript/dom/index.tsx',
      '/Users/node_modules/@typescript/dom/index.d.ts',
      '/Users/node_modules/@types/typescript__dom/package.json',
      '/Users/node_modules/@types/typescript__dom.d.ts',
      '/Users/node_modules/@types/typescript__dom/index.d.ts',
      '/node_modules/@typescript/dom/package.json',
      '/node_modules/@typescript/dom.ts',
      '/node_modules/@typescript/dom.tsx',
      '/node_modules/@typescript/dom.d.ts',
      '/node_modules/@typescript/dom/index.ts',
      '/node_modules/@typescript/dom/index.tsx',
      '/node_modules/@typescript/dom/index.d.ts',
      '/node_modules/@types/typescript__dom/package.json',
      '/node_modules/@types/typescript__dom.d.ts',
      '/node_modules/@types/typescript__dom/index.d.ts',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom.js',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom.jsx',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/index.js',
      '/Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/index.jsx',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom.js',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom.jsx',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/index.js',
      '/Users/ortatherox/dev/typescript/node_modules/@typescript/dom/index.jsx',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/dev/node_modules/@typescript/dom.js',
      '/Users/ortatherox/dev/node_modules/@typescript/dom.jsx',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/index.js',
      '/Users/ortatherox/dev/node_modules/@typescript/dom/index.jsx',
      '/Users/ortatherox/node_modules/@typescript/dom/package.json',
      '/Users/ortatherox/node_modules/@typescript/dom.js',
      '/Users/ortatherox/node_modules/@typescript/dom.jsx',
      '/Users/ortatherox/node_modules/@typescript/dom/index.js',
      '/Users/ortatherox/node_modules/@typescript/dom/index.jsx',
      '/Users/node_modules/@typescript/dom/package.json',
      '/Users/node_modules/@typescript/dom.js',
      '/Users/node_modules/@typescript/dom.jsx',
      '/Users/node_modules/@typescript/dom/index.js',
      '/Users/node_modules/@typescript/dom/index.jsx',
      '/node_modules/@typescript/dom/package.json',
      '/node_modules/@typescript/dom.js',
      '/node_modules/@typescript/dom.jsx',
      '/node_modules/@typescript/dom/index.js',
      '/node_modules/@typescript/dom/index.jsx'
    ]
  },
  currentDirectory: '/Users/ortatherox/dev/typescript/repros/tsLibOverrides'
}

What I want: /Users/ortatherox/dev/typescript/repros/tsLibOverrides/node_modules/@typescript/dom/index.d.ts
Closest I get: /Users/ortatherox/dev/typescript/repros/node_modules/@typescript/dom/index.d.ts

Perhaps instead of currentDirectory I need to append a filename to force it to look in node_modules of the currentDir.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta

Orta Therox (orta) commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

Confirming to myself:

Revised code:

var localOverride = ts.resolveModuleName("@typescript/" + path, currentDirectory + "/tsconfig.json", { moduleResolution: ts.ModuleResolutionKind.NodeJs }, host);
console.log({ libFileName, localOverride, currentDirectory  })

Does:

$ /Users/ortatherox/dev/typescript/repros/tsLibOverrides/node_modules/.bin/tsc
{
  libFileName: 'lib.dom.d.ts',
  localOverride: {
    resolvedModule: {
      resolvedFileName: '/Users/ortatherox/dev/typescript/repros/tsLibOverrides/node_modules/@typescript/dom/index.d.ts',
      originalPath: undefined,
      extension: '.d.ts',
      isExternalLibraryImport: true,
      packageId: [Object]
    },
    failedLookupLocations: [
      '/Users/ortatherox/dev/typescript/repros/tsLibOverrides/node_modules/@typescript/dom.ts',
      '/Users/ortatherox/dev/typescript/repros/tsLibOverrides/node_modules/@typescript/dom.tsx',
      '/Users/ortatherox/dev/typescript/repros/tsLibOverrides/node_modules/@typescript/dom.d.ts'
    ]
  },
  currentDirectory: '/Users/ortatherox/dev/typescript/repros/tsLibOverrides'
}

The fact that whether the file exists is irrelevant (and so I think tsconfig.json is a bad call because it would feel like a mis-direction for someone reading) but it's not a very satisfying answer.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta
Fix the build
e2ca4b5
@orta

Orta Therox (orta) commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

Looking through the code, this isn't necessarily on a hot route but this does affect isSourceFileDefaultLibrary which is called a bit in the watcher. I did successfully get a module cache not crashing via createModuleResolutionCache real late in the process but never resolved a successful result.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta

Orta Therox (orta) commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

TypeScript Bot (@typescript-bot) pack this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at e2ca4b5. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey Orta Therox (@orta), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/110482/artifacts?artifactName=tgz&fileId=D48E94F3C6C5280C83D295B2BD91EAE9FE2072B484565ED195437AEED0CAB59C02&fileName=/typescript-4.5.0-insiders.20210914.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta
Add cache
9943525
weswigham
Wesley Wigham (weswigham) approved these changes Sep 14, 2021
View reviewed changes
@saschanaz Kagami Sascha Rosylight (saschanaz) mentioned this pull request Sep 14, 2021
Consider splitting dom lib events out into separate lib for nodejs use #43972
Open
andrewbranch
Andrew Branch (andrewbranch) requested changes Sep 15, 2021
View reviewed changes

@andrewbranch Andrew Branch (andrewbranch) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

One nit then excited to try this out

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/program.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@orta
Better naming
853ac55
andrewbranch
Andrew Branch (andrewbranch) requested changes Sep 15, 2021
View reviewed changes
Comment thread src/compiler/program.ts Outdated
if (localOverride?.resolvedModule) {
return localOverride.resolvedModule.resolvedFileName;

const resolveFrom = combinePaths(currentDirectory, `/__lib_node_modules_lookup_${libFileName}__.ts`);

@andrewbranch Andrew Branch (andrewbranch) Sep 15, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This always ignores currentDirectory because the latter argument is absolute.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewbranch Andrew Branch (andrewbranch) Sep 15, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Guessing this didn’t break tests only because all the tests are rooted at /

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@orta Orta Therox (orta) Sep 15, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nice spot!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Orta Therox (orta) added 2 commits September 15, 2021 19:46
@orta
Merge branch 'main' of https://github.com/microsoft/TypeScript into l…
2725d3c
…ibTS
@orta
Fixes the lookup path
77c0e2e
@orta

Orta Therox (orta) commented Sep 15, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I explored setting the node_modules to not be root, but the currentDir is src in tests while unrooted files live at tests/cases/compiler/ in tests - so I either make it all arbitrary or I keep it just as arbitrary with a rooted node_modules

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andrewbranch
Andrew Branch (andrewbranch) approved these changes Sep 15, 2021
View reviewed changes
@orta
Orta Therox (orta) merged commit b2f9432 into microsoft:main Sep 15, 2021
This was referenced Sep 17, 2021
Support having '@types/web' as overriding 'dom' in TypeScript's lib resolver #44795
Closed
Proposal: Lookup lib files from individual node packages before falling back to builtin libs #45685
Closed
@delucis Chris Swithinbank (delucis) mentioned this pull request Sep 19, 2021
Support custom/non-vendor modules for lib #45959
Closed
5 tasks done
@saschanaz Kagami Sascha Rosylight (saschanaz) mentioned this pull request Sep 19, 2021
Support overriding lib (e.g. lib.dom.d.ts) paths #29237
Closed
5 tasks done
@orta Orta Therox (orta) mentioned this pull request Sep 24, 2021
Resolve with -lib in TypeScript lib lookup via node-style resolution #46046
Merged
This was referenced Sep 29, 2021
HTMLCanvasElement.transferControlToOffscreen() removed from lib.dom.d.ts #45745
Closed
lib.es3.d.ts for DefinitelyTyped libraries with legacy support #46130
Closed
@mikob

Miko (mikob) commented Oct 20, 2021

Copy link
Copy Markdown

Orta Therox (@orta)

All JS dependency managers support this syntax:

has this been tested with yarn 3+? I get this error:

➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: @typescript/lib-dom@npm:@types/web isn't supported by any available resolver
    at Xc.getResolverByDescriptor (/home/mikob/workspace/lipsurf/.yarn/releases/yarn-3.0.2.cjs:294:5330)
    at Xc.bindDescriptor (/home/mikob/workspace/lipsurf/.yarn/releases/yarn-3.0.2.cjs:294:4719)
    at p (/home/mikob/workspace/lipsurf/.yarn/releases/yarn-3.0.2.cjs:303:6959)
    at async Promise.all (index 1)
    at async Fe.resolveEverything (/home/mikob/workspace/lipsurf/.yarn/releases/yarn-3.0.2.cjs:303:8166)
indykish reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mikob

Miko (mikob) commented Oct 20, 2021

Copy link
Copy Markdown

seems like a yarn issue, workaround here: yarnpkg/berry#1621

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta

Orta Therox (orta) commented Oct 21, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Did you use yarnpkg/berry#1621 (comment) e.g.:

"resolutions": {
  "@typescript/lib-dom": "npm:@types/web@*"
}

With yarn add @typescript/lib-dom after? (We can add this to the types/web README)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mikob

Miko (mikob) commented Oct 21, 2021

Copy link
Copy Markdown

I went the other route and just specified @* at the end of the dependency line.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alshdavid

David Alsh (alshdavid) commented Nov 3, 2021

Copy link
Copy Markdown

Can this be imported explicitly without globals being set?
eg

import { window, Window, console } from '@typescript/lib-dom'
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dlemfh

Drew Lee (이드로) (dlemfh) commented Nov 3, 2021

Copy link
Copy Markdown

Great work! 👍

May I ask is it possible to use this feature to enforce my project to use specific node types e.g. @types/node@^14.17.0, while my dependency uses @types/node@^16?

What would I need to do if I wanted to not use node types altogether, even when my dependency is using node types?

Concrete use case would be: a dependency library (which uses node types) forcibly introduces type overrides for setTimeout, while my project (a web project) only ever needs the DOM version of setTimeout. I want to prevent @types/node from polluting my "type space".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orta

Orta Therox (orta) commented Nov 3, 2021

Copy link
Copy Markdown
Contributor Author

Can this be imported explicitly without globals being set?

No, that's being researched over at #43972

May I ask is it possible to use this feature to enforce my project to use specific node types?

I don't think this can be too useful there - I think you might need some sort of pre-install script which checks. In theory #40468 could allow for it, but the underlaying issue is that everything in TS lives in a global type space and this at least lets you edit the 'ships with typescript' globals

dlemfh reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nsmithdev Nathan Smith (nsmithdev) mentioned this pull request Dec 4, 2021
Error: node_modules/twilio-video/tsdef/VideoProcessor.d.ts:2:34 - error TS2304: Cannot find name 'OffscreenCanvas'. twilio/twilio-video.js#1629
Open
@renchap Renaud Chaput (renchap) mentioned this pull request Apr 8, 2022
Installing with yarn berry doesn't work JustFly1984/react-google-maps-api#2980
Closed
@iainjreid Iain J. Reid (iainjreid) mentioned this pull request Apr 27, 2022
Split the ES5 library definitions into their own files #48863
Open
@cdaringe

Christopher Dieringer (cdaringe) commented Jan 25, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

it's not clear to me exactly how to use this, having read the associated blog post.

  • i have a custom runtime (an emulator for a homegrown system with some globals)
  • it looks like we can only use existing lib names, so I'll attempt to squash "dom" as a proxy for my emulator types
  • using pnpm syntax, i'm linking in my lib DOM replacement via:
  "dependencies": {
     // ...snip...
    "@typescript/lib-dom": "workspace:concordance-env@*"
  },
$ tree node_modules/\@typescript/lib-dom/src/
node_modules/@typescript/lib-dom/src/
└── index.d.ts
# all my good stuff!
// index.d.ts
declare var foobar: number;

and specifying:

{
  "extends": "concordance-tsconfig/tsconfig.base.json",
  "compilerOptions": {
    // DOM is squashed with concordance env :)
    "lib": ["DOM"]
  }
}

but the compiler isn't picking up my symbols 🤔, such as foobar: number, as declared above.

did I miss a crucial step?

update--i had an import in my .d.ts which broke it :). removing the import made the symbols pick up.

Dan1ve reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Jan 25, 2023

Copy link
Copy Markdown
Member

Glad you figured it out, but it sounds like this feature isn’t what you want anyway. You’ve always been able to add arbitrary global type declaration files via the "types" key in tsconfig.json if they’re in a node_modules package, or "files"/"include" if they’re local, or /// <reference path="./path/to/globals.d.ts" /> to name a few. What this feature allows you to do is replace existing built-in lib types, like lib.dom.d.ts, while not breaking other dependencies that declare a dependency on those built-ins. If you just want to add global types to your compilation, just include your .d.ts file as you would any other, via one of the methods I mentioned above.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cdaringe

Christopher Dieringer (cdaringe) commented Feb 2, 2023

Copy link
Copy Markdown

hey Andrew Branch (@andrewbranch), thanks!

You've always been able to add arbitrary global types

kind of! set me straight. these are the kind of global types inclusion by types config field and/or triple-slashes:

/// <reference path="..." /> - assumes types are local to my project (they're not!)
/// <reference types="..." /> - assumes they are @types/ prefixed node packages
/// <reference lib="..." /> - isn't a general "lib", is an enum of env specific libs

what's missing is:

/// <reference package="..." from my perspective.

due to reasons, i cannot publish to DefTyped. feasibly i could path="../../node_modules/foo/bar/index.d.ts, but that's cumbersome in my particular codebase.

for that reason, i thought "well, i could feasibly intercept one of the lib resolvers!". it ended up having other quirks, so i may pick a new path. but i'd love to have a <reference package-name='...' /> for this reason

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Feb 2, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Off the top of my head, I’m pretty sure both the "types" array and /// <reference types="..." /> prefer looking up in typeRoots (i.e. node_modules/@types by default) first, but will fall back to looking for the plain package name in node_modules. Am I wrong about that? You can use tsc --traceResolution to audit the process used for every import and triple-slash directive to be sure.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cdaringe

Christopher Dieringer (cdaringe) commented Feb 2, 2023

Copy link
Copy Markdown

Holy guacamole, why didnt i even try!? The docs are adequate, but I misinterpreted them. Thx

andrewbranch reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheetalkamat Sheetal Nandi (sheetalkamat) mentioned this pull request Feb 14, 2023
pathForLibFile needs improvement in program reuse, default library detection and other uses #52759
Closed
@Krisztiaan Krisztiaan (Krisztiaan) mentioned this pull request Feb 21, 2023
Add one-liner quick start to readme mattpocock/ts-reset#34
Closed
@jakebailey Jake Bailey (jakebailey) mentioned this pull request Jan 22, 2025
Add new option "libReplacement" #60829
Merged
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@andrewbranch Andrew Branch (andrewbranch) andrewbranch approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@orta Orta Therox (orta)

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@orta @typescript-bot @mikob @alshdavid @dlemfh @cdaringe @andrewbranch @weswigham
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.