| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) perf test |
Sorry, something went wrong.
|
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! |
Sorry, something went wrong.
|
Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at daa99ce. You can monitor the build here. |
Sorry, something went wrong.
|
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/pr-build@4.5.0-pr-45771-3".; |
Sorry, something went wrong.
|
Orta Therox (@orta) Comparison Report - main..45771
System
Hosts
Scenarios
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
|
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 Perhaps instead of currentDirectory I need to append a filename to force it to look in node_modules of the currentDir. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) pack this |
Sorry, something went wrong.
|
Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at e2ca4b5. You can monitor the build here. |
Sorry, something went wrong.
|
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/pr-build@4.5.0-pr-45771-10".; |
Sorry, something went wrong.
There was a problem hiding this comment.
One nit then excited to try this out
Sorry, something went wrong.
| if (localOverride?.resolvedModule) { | ||
| return localOverride.resolvedModule.resolvedFileName; | ||
|
|
||
| const resolveFrom = combinePaths(currentDirectory, `/__lib_node_modules_lookup_${libFileName}__.ts`); |
There was a problem hiding this comment.
This always ignores currentDirectory because the latter argument is absolute.
Sorry, something went wrong.
There was a problem hiding this comment.
Guessing this didn’t break tests only because all the tests are rooted at /
Sorry, something went wrong.
There was a problem hiding this comment.
nice spot!
Sorry, something went wrong.
|
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 |
Sorry, something went wrong.
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)
|
Sorry, something went wrong.
|
seems like a yarn issue, workaround here: yarnpkg/berry#1621 |
Sorry, something went wrong.
|
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) |
Sorry, something went wrong.
|
I went the other route and just specified @* at the end of the dependency line. |
Sorry, something went wrong.
|
Can this be imported explicitly without globals being set? import { window, Window, console } from '@typescript/lib-dom' |
Sorry, something went wrong.
|
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". |
Sorry, something went wrong.
No, that's being researched over at #43972
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 |
Sorry, something went wrong.
|
it's not clear to me exactly how to use this, having read the associated blog post.
"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. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
hey Andrew Branch (@andrewbranch), thanks!
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!) 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 |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
Holy guacamole, why didnt i even try!? The docs are adequate, but I misinterpreted them. Thx |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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:
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.