Skip to content
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

fix #2388: allow consuming types without dom types #3679

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

remcohaszing
Copy link
Contributor

Currently the TypeScript types for esbuild depend on the DOM types. However, esbuild itself does not depend on the DOM.

This change uses type augmentation to make the type error go away, while keeping backwards support for use with the DOM types.

Closes #2388

remcohaszing and others added 2 commits March 5, 2024 11:31
Currently the TypeScript types for esbuild depend on the DOM types.
However, esbuild itself does not depend on the DOM.

This change uses type augmentation to make the type error go away, while
keeping backwards support for use with the DOM types.

Closes evanw#2388
@evanw
Copy link
Owner

evanw commented Mar 7, 2024

Ok, I can give this a try, but I reserve the right to revert this if it causes other problems. It looks like avoiding dom types also requires URL to be defined, so I'll add that too.

Seems kind of weird for using esbuild to be polluting the global type scope, but I guess that's just how TypeScript works. It's too bad TypeScript doesn't have some sort of if typeof WebAssembly !== 'undefined' for types.

@evanw evanw merged commit c809af0 into evanw:main Mar 7, 2024
9 checks passed
@remcohaszing remcohaszing deleted the fix-domless-types branch March 8, 2024 07:37
@remcohaszing
Copy link
Contributor Author

I reserve the right to revert this if it causes other problems

Of course you do! You are the maintainer ❤️

It looks like avoiding dom types also requires URL to be defined, so I'll add that too.

Nice catch! This is less apparent, as people often use the dom types or @types/node, both if which specify URL.

Seems kind of weird for using esbuild to be polluting the global type scope, but I guess that's just how TypeScript works. It's too bad TypeScript doesn't have some sort of if typeof WebAssembly !== 'undefined' for types.

You can, but it’s quite hacky. (playground link)

type Fallback = never

// @ts-ignore
type InternalURL = any extends URL ? Fallback : URL

This only works from handwritten type definition files, not from TypeScript source files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot find namespace 'WebAssembly'
2 participants