TypeScript-DOM-lib-generator
TypeScript-DOM-lib-generator copied to clipboard
Feature request: split whatwg definitions in separate files
Use case
I want to write an isomorphic library that runs in the browser and nodejs. I want to make sure that I only rely on globals that are available in both environments. Currently, to do this, I must use lib: ["dom"] and types: ["node"], which results in defined globals that are not actually available in both runtime envs, leading to a fake sense of type safety when writing code.
Suggested solution
As a user of typescript, I would like to be able to pick more precisely the libs I depend on. For example: lib: ["es2022", "whatwg.url", "whatwg.fetch"]
There would be a lot of benefit to doing this:
@types/nodewould not have to re-define definitions already provided bytypescript(new URL(u as URL)incorrectly yields an error when usingtypes: ["node"])- All libraries targeting both dom & scripthost envs would benefit from improved type safety
Related issues
- https://github.com/microsoft/TypeScript/issues/41727
- https://github.com/microsoft/TypeScript/issues/31535