You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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"]
andtypes: ["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 bytypescript
(new URL(u as URL)
incorrectly yields an error when usingtypes: ["node"]
)Related issues
The text was updated successfully, but these errors were encountered: