-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support having '@types/web' as overriding 'dom' in TypeScript's lib resolver #44795
Comments
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 |
Great thinking @MartinJohns @sandersn was interested in having modules in {
compilerOptions: {
lib: ["es2015", { name: "dom", module: "@types/web" }]
}
} |
What are the reasons? You didn't fill out the "Motivating Example" and "Use Cases" sections of the issue template. :-P |
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,
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 |
Another thing to consider: what is the right way to declare a dependency on |
I think this syntax makes it very explicit what is going on: {
compilerOptions: {
lib: ["es2015", { replace: "dom", with: "@types/web" }]
}
} However it brings its own problems, because there's a question of how should this act: {
compilerOptions: {
lib: [{ replace: "dom", with: "@types/web" }]
}
} Should it act like: I think it should probably act like: |
#45771 shipped this into the TypeScript 4.5 - the answer was to leave dependency managers to handle the resolution
|
@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 I'm wondering if this would be the way to do it or I'm looking at the wrong place |
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 |
We have the right node types and I thought this feature was going to enable to skip the 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 |
Suggestion
I'd like to be able to install
@types/web
and have the following happen:/// <reference lib="dom">
do not resolve to the vendoredlibdom.d.ts
dom
in a project vialib
would automatically pick up@types/web
(or be fully suppressed)🔍 Search Terms
dom types/web web lib
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
dom
->@types/web
inside the TS compiler's@types/web
1 - Hardcoding
Pros:
@types/web
is 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 dts files before we can reliably use the files in
lib
The text was updated successfully, but these errors were encountered: