You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support having '@types/web' as overriding 'dom' in TypeScript's lib resolver #44795
Hardcode some sort of dom -> @types/web inside the TS compiler's
Support some kind of pragma in @types/web
1 - Hardcoding
Pros: @types/webis a special case (though there could be more in the future) and this could be the smallest possible change.
Cons:
It feels a bit meh.
2 - Pragmas
Pros:
We have existing pragmas: /// <reference no-default-lib="true"/> for type of thing. This answer is totally generic and would allow others to have their own implementations of other deployed libs.
Cons:
I'd need to check, but this might mean looking for the pragmas across all Types (@types) dts files before we can reliably use the files inlib
With the pragma approach, what would happen if two packages aim to replace the definitions? This could easily happen with unfortunate dependencies.
A third option may be to have it explicitly configured in the tsconfig.json. I'm the last person who'd ask for yet another flag / option, but it sounds sensible for this. This would allow replacement of any library file, and it's explicit (no magic).
Reacted by Orta Therox, Andrii Dieiev and Daniel Rosenwasser
Nathan Shively-Sanders (@sandersn) was interested in having modules in lib for other reasons I think, I wonder if could be solved with the same concept:
Chatted with wes (and I've marked this issue for design review tomorrow) but I'm mostly pretty convinced that a pragma is the right route here now that I understand that we basically read all the visible source-code before adding lib to a compile for type checking. So the cons for 2 don't apply.
I personally think if we hit a dupe we should throw, but realistically they would probably raise an error due to duplicated types anyway. Will see what happens at the language review meeting.
I might've missed some other context that was already discussed, but I don't think a pragma on its own is the right solution. Over time, .d.ts files getting published that say "no no no, let me tell you what to load" end up falling in conflict with what the end-user wants.
I personally think if we hit a dupe we should throw,
If we do end up shipping another pragma that seems reasonable, but it means we have to think about how a user can put their foot down and say exactly what gets loaded. The benefit of that is that you can give an error message saying "these two libraries conflict in what they're asking for".
I think ultimately, TypeScript users need to be able to control the environment that gets checked, and tsconfig.json needs to allow controlling that.
#45771 shipped this into the TypeScript 4.5 - the answer was to leave dependency managers to handle the resolution
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.
Orta Therox (@orta) is there documentation for this? I'd like to have some DOM types like top level URLSearchParams in node applications but I don't want to add dom to libs. I'd like to only have whatever node version X supports.
I'm wondering if this would be the way to do it or I'm looking at the wrong place
We have the right node types and types: ["node"] which works for everything except for these shared browser globals, so I need to also add libs: ["dom"] to access these globals which are also available in node.
I thought this feature was going to enable to skip the libs: ["dom"] under these circumstances because I was under the impression that the node types don't have these globals because it conflicts with the bundled dom ones?
I'm sorry if this is really off-topic but I seem to be missing something obvious here o:
This feature lets you replace the lib files which ship with TypeScript in your projects. You could replace the dom lib with your custom subset but that's overcomplicating things when you can instead add the file to your project and not import the default dom at all.
So, no matter what, I need some form of dom instead of having the correct node types with all the available node globals? Alright, I guess. Seems a bit awkward but thanks for your guidance
Activity
MartinJohns commentedon Jun 29, 2021
With the pragma approach, what would happen if two packages aim to replace the definitions? This could easily happen with unfortunate dependencies.
A third option may be to have it explicitly configured in the
tsconfig.json. I'm the last person who'd ask for yet another flag / option, but it sounds sensible for this. This would allow replacement of any library file, and it's explicit (no magic).orta commentedon Jun 29, 2021
Great thinking Martin Johns (@MartinJohns)
Nathan Shively-Sanders (@sandersn) was interested in having modules in
libfor other reasons I think, I wonder if could be solved with the same concept:MartinJohns commentedon Jun 29, 2021
What are the reasons? You didn't fill out the "Motivating Example" and "Use Cases" sections of the issue template. :-P
orta commentedon Jun 29, 2021
Chatted with wes (and I've marked this issue for design review tomorrow) but I'm mostly pretty convinced that a pragma is the right route here now that I understand that we basically read all the visible source-code before adding lib to a compile for type checking. So the cons for 2 don't apply.
I personally think if we hit a dupe we should throw, but realistically they would probably raise an error due to duplicated types anyway. Will see what happens at the language review meeting.
DanielRosenwasser commentedon Jul 2, 2021
I might've missed some other context that was already discussed, but I don't think a pragma on its own is the right solution. Over time,
.d.tsfiles getting published that say "no no no, let me tell you what to load" end up falling in conflict with what the end-user wants.If we do end up shipping another pragma that seems reasonable, but it means we have to think about how a user can put their foot down and say exactly what gets loaded. The benefit of that is that you can give an error message saying "these two libraries conflict in what they're asking for".
I think ultimately, TypeScript users need to be able to control the environment that gets checked, and
tsconfig.jsonneeds to allow controlling that.DanielRosenwasser commentedon Jul 2, 2021
Another thing to consider: what is the right way to declare a dependency on
@types/webif you're a library?peerDependency?Adds docs + scripts for deployment to TypeScript
orta commentedon Aug 19, 2021
I think this syntax makes it very explicit what is going on:
However it brings its own problems, because there's a question of how should this act:
Should it act like:
lib: []orlib: undefined?I think it should probably act like:
lib: []- but it'll need documenting somewhere.orta commentedon Sep 17, 2021
#45771 shipped this into the TypeScript 4.5 - the answer was to leave dependency managers to handle the resolution
alfaproject commentedon Feb 22, 2022
Orta Therox (@orta) is there documentation for this? I'd like to have some DOM types like top level URLSearchParams in node applications but I don't want to add
domto libs. I'd like to only have whatever node version X supports.I'm wondering if this would be the way to do it or I'm looking at the wrong place
orta commentedon Feb 22, 2022
You'd need to add the types you want to your own .d.ts file which affects global scope, it's not related to this feature
alfaproject commentedon Feb 22, 2022
We have the right node types and
types: ["node"]which works for everything except for these shared browser globals, so I need to also addlibs: ["dom"]to access these globals which are also available in node.I thought this feature was going to enable to skip the
libs: ["dom"]under these circumstances because I was under the impression that the node types don't have these globals because it conflicts with the bundleddomones?I'm sorry if this is really off-topic but I seem to be missing something obvious here o:
orta commentedon Feb 23, 2022
This feature lets you replace the lib files which ship with TypeScript in your projects. You could replace the dom lib with your custom subset but that's overcomplicating things when you can instead add the file to your project and not import the default dom at all.
alfaproject commentedon Feb 23, 2022
So, no matter what, I need some form of
dominstead of having the correctnodetypes with all the available node globals? Alright, I guess. Seems a bit awkward but thanks for your guidance