TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

Feature request: split whatwg definitions in separate files

Open matthieusieben opened this issue 1 year ago • 0 comments

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/node would not have to re-define definitions already provided by typescript (new URL(u as URL) incorrectly yields an error when using types: ["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

matthieusieben avatar Feb 06 '24 10:02 matthieusieben