Support having '@types/web' as overriding 'dom' in TypeScript's lib resolver
See original GitHub issueSuggestion
I’d like to be able to install @types/web
and have the following happen:
- Other dependencies (like from DT) using something like
/// <reference lib="dom">
do not resolve to the vendoredlibdom.d.ts
- The default inclusion of
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:
- This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- This wouldn’t change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- x ] This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript’s Design Goals.
⭐ Suggestion
- Hardcode some sort of
dom
->@types/web
inside the TS compiler’s - Support some kind of pragma in
@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 inlib
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 4.5
TypeScript 4.5 introduces a way to override a specific built-in lib in a manner similar to how @types/ support works. When deciding which...
Read more >What's new in TypeScript 4.5 - LogRocket Blog
TypeScript 4.5 includes enhanced Awaited type, supported lib from ... @types/web represents TypeScript's published versions of the DOM APIs.
Read more >Announcing TypeScript 4.5 Beta - Microsoft Developer Blogs
ECMAScript Module Support in Node.js; Supporting lib from ... today TypeScript publishes versions of the DOM APIs on @types/web .
Read more >Understanding Advanced TypeScript Concept & Types
Know what are advanced typescript concepts, type assertions & aliases ... to @types/ support allows you to override a specific built-in lib.
Read more >typescript - How can I override a variable's type which has ...
According to Titian Cernicova-Dragomir, I can't achieve this without modifying TypeScript's built-in lib.dom.d.ts .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
#45771 shipped this into the TypeScript 4.5 - the answer was to leave dependency managers to handle the resolution
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).