-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Conditionally add node/DOM types to StructuredCloneable #908
Conditionally add node/DOM types to StructuredCloneable #908
Conversation
f30d40b
to
b832cdb
Compare
Created a related PR, #912, that makes the type checks properly fail for the current scenario. Would be good to get work on that in tandem with this. I also think we should find a model where we test the types in contexts where eg. both the |
fb30867
to
d6f8109
Compare
source/find-global-type.d.ts
Outdated
|
||
Use-case: Conditionally referencing DOM types only when the DOM library present. | ||
|
||
*Limitations:* Due to peculiarities with the behavior of `globalThis`, "globally defined" has a narrow definition in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend opening a TypeScript issue about this limitation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The odd behavior itself is correct (microsoft/TypeScript#39504), so there's nothing to be done on that front. In terms of avoiding this hack in the first place, there's already an issue regarding that: microsoft/TypeScript#31894
Thanks for contributing 🙏 |
While investigating #899, I discovered a solution that lets us only include DOM/Node types if they actually exist. Based on this code from the node type declarations, I came up with this solution:
This only works with types that have a public constructor in
globalThis
, butBlob
,File
, and all the DOM types appear to have constructors and work like this. In order to verify that all the DOM types have public constructors I added@webgpu/types
,@types/dom-webcodecs
, and@types/webxr
, which got me most of the types I was missing, then I created this file to manually check them:Fixes #899