Let TypeScript resolve deps in lib files + allow external tools to extend the lib support - #64
Conversation
|
|
||
| enqueue(''); | ||
| enqueue('es6'); | ||
| enqueue('es2015'); |
There was a problem hiding this comment.
Adding the ES6 means that we can use the TS lib routing pattern 1-to-1, it adds 3-4 LOC (and then the copyright banner)
| case 1: | ||
| case 0: | ||
| return "lib.d.ts"; | ||
| } |
There was a problem hiding this comment.
This should be future proof for ES2021 etc
…tend the lib support
4a2d1d2 to
1d6f5a0
Compare
|
Would this allow to load the ES libs but without the DOM APIs? I use the editor in a scripting environment where the DOM APIs are not present, except for one specific use case. So right now for that to work I have to set |
|
I've not tested trying without the DOM (I tested that it explicitly did, go figure) but I assume it would work that way because TypeScript works that way and all lib routing happens through it. The PR also has an intentional way to let you set this up. You can override any DTS file via the |
|
( Also this is running on the 4.0 playground: https://www.staging-typescript.org/play?ts=4.0.0-beta ) |
Co-authored-by: Wesley Wigham <wwigham@gmail.com>
Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
|
This PR got an update: the lib d.ts files are now represented as Monaco in-memory models. This allows for features like peek to work, and for people to reliably show the files in their Monaco instances. |
|
I'd like to come look at this again at some point and make it so lib files don't type check, which can avoid the dancing in a213b30 |
… into let_ts_resolve_libs
|
When I checked Now it does, this example is set to Doing this bumps the |
|
Followed to this PR from microsoft/TypeScript-Website#82 I am still experiencing...
...in both playground and staging playground, indicating Object.entries is missing within Typescript playground when choosing 4.0.0-beta and target esnext. Do we need to wait a while for this work to be stably deployed to the typescriptlang server? |
|
I can now see this functioning in the 4.0.2 version live on typescriptlang.org |
|
Ah yeah, sorry for missing that - it would have worked on nightlies too! |
There was a problem hiding this comment.
Hey Orta Therox (@orta) I just pushed a couple of commits to simplify the code (without changing any of the import logic) and to address some stylistic issues.
But when I run npm run prepublishOnly on my machine, here are the file sizes I get:
- [NOK]
release/min/tsMode- 1.5M (from a previous size of 23.9K) - [OK]
release/min/tsWorker- 3.8M (from a previous size of 3.3M)
This is caused by the new reference to lib/lib.ts in languageFeatures.ts. This ends up requiring the entire lib.d.ts contents on the UI thread.
|
I've modified the usages in |
|
Hey Alexandru Dima (@alexdima) - thanks for the thorough look though |
Hi Orta Therox (@orta), since this is now merged I tried running it out of sources to test my use case from above, but I'm running into some problems (or maybe I misunderstood this PR 😅 ). My instinct was that this PR enables the following code, where I can set monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ESNext,
lib: ["esnext"],
allowNonTsExtensions: true
});
// monaco.languages.typescript.javascriptDefaults.addExtraLib("", "lib.dom.d.ts");
monaco.editor.create(document.getElementById("container"), {
value: "",
language: "javascript"
}); |
|
Interesting, maybe with: But switching it to |
|
Sebastian Pahnke (@spahnke) Hi! I'm having the exact same problem, |
|
My code from above now works in the current version of the editor (e.g. in the playground); the issue has been fixed with #68. You should be able to just use monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ESNext,
lib: ["esnext"],
allowNonTsExtensions: true
});
monaco.editor.create(document.getElementById("container"), {
value: "",
language: "javascript"
}); |
|
Ah, you should be able to just do monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ESNext,
lib: ["es2019", "dom"],
allowNonTsExtensions: true
});instead of that line to empty the extra lib. That's what I use to switch between browser ( |






Previously: we bundled 2 DTS lib files and hardcoded the paths into the TS workers.
This PR:
<reference lib='lines which are now back_extraLibsoption to allow others (e.g. the playground) to add the rest of the DTS files at runtime