-
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
Extract APIs that are common to Node and the DOM to their own namespace #41727
Comments
There's a growing Venn diagram here with Webworkers; the truth is that we don't even like maintaining the DOM types and sent Node to community management, so our appetite for tackling this is quite low. Maybe someone can automate a process that produces good lib files based on intersection -- if that required a few tweaks on our side to make work right, we'd be interested to help out. |
@RyanCavanaugh I'm sorry, I miss a little bit of context here. I assume when you say "we sent Node to community management", you mean that Node types are currently contributed/maintained by people that are not members of the TypeScript team at Microsoft. Is it correct? If yes, can you identify people or groups that are currently taking responsibility for those? Same question for the DOM, do you know which people or groups might be best suited to take responsibility or that currently do and might want help? Any pointer to organise an hypothetical effort very welcome! Also, do you currently have any automated type generation tool for the DOM or Node? Have you ideas about suitable sources of data to base a generator on? |
Correct
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts For the DOM, the project is https://github.com/microsoft/TypeScript-DOM-lib-generator and it's maintained by us. Node doesn't have a machine-readable spec AFAIK so there's nothing to generate from. |
IMO (and these aren't necessarily dependent on each other)
However it's not clear the best way to do that. |
I would like to second this with another use case as example. When you want to write an isomorphic library that runs both in the browser and in node, there is not a single lib/types files that you can use to make your code actually type safe. Let' say you want your lib to use It would be very helpful if, as a TS user, I could easily target environments using
There should be little added work in the TS repo ("just" a file split) but a huge benefit for the community ❤️ |
Search Terms
Cannot find name 'URL'
,Cannot find name 'TextEncoder'
,Cannot find name 'TextDecoder'
, WHATWG URL API, Node JS URL API, URL type, common APIs, universal APIs, node and browser compatibility, dom lib types node.Suggestion
Move APIs that are common to node and the browser out of
lib.dom.d.ts
into their own file and import them fromlib.dom.d.ts
. For example, in the case of the URL Web API, move it tolib.dom.url.d.ts
.Which would allow in tsconfig to add
dom.url
to thelib
entry of thecompilerOptions
instead of the wholedom
namespace, which is probably a bad idea for projects targeting Node.js:Note: this wouldn't even affect people requiring the DOM type definitions, only allow more granular control. I would probably like to add two layers: 1.
lib.common.d.ts
for all APIs that are present in both environment; and 2.lib.dom.url.d.ts
,lib.dom.textencoder.d.ts
,lib.dom.textdecoder.d.ts
... for each relevant feature that may not be present in all Node versions.Use Cases
There is a growing list of dom APIs which are being implemented in node, it seems necessary to have a proper targeting solution that doesn't lead to misleading autocompletion or weird workarounds (I haven't found anything satisfying in that area).
Examples
Anyone using APIs common to Node.js and the browser wanting to add the APIs present in their node global namespace (but not all of the dom APIs). For example using Node's WHATWG URL API instead of the legacy URL API and avoiding the
Cannot find name 'URL'
errors.Checklist
My suggestion meets these guidelines:
Linked issues
The text was updated successfully, but these errors were encountered: