-
Notifications
You must be signed in to change notification settings - Fork 309
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
feat: transform Request, Response, and WebSocket classes to interfaces with var declarations #2708
Conversation
All contributors have signed the CLA ✍️ ✅ |
This looks good to me! It would be great to see the diff of types generated with this turned on vs with this turned off, to verify the behaviour is correct |
@penalosa This gist shows a comparison of the new vs old generated types: https://gist.github.com/andyjessop/ca8456d22b2abb44542143d55c196040 |
I have read the CLA Document and I hereby sign the CLA |
f76df21
to
cfd832b
Compare
Could this have broken types for Node.js compatibility like: |
Currently |
This PR is part of the drive for Node.js compatibility and focusses on ensuring 3 specific interfaces,
Request
,Response
, andWebSocket
, are compatible with@types/node
.The maintainers of
@types/node
considered a related use case when addingfetch
types to Node, because it's relatively common forlib.dom
and@types/node
to be loaded together, which would cause similar conflicts to what we're seeing now.Because of that, they use this pattern when defining a web type:
This defers to the global
Response
type if it's available, falling back toundici
otherwise.In order to get this to work for us, we need to declare
declare var onmessage: never
, thenResponse
will be ourResponse
.Next, we need to get these three interfaces onto
globalThis
. In order to do that, ourclass
delcarations need to be converted tovar
declarations. And in order to get the same type of behaviour (e.g. in return types), we need a corresponding interface. For example:Implementation
This PR creates two transformers that will transform our types in the worker:
createAddOnMessageDeclarationTransformer
- adds theonmessage
declaration.createClassToInterfaceTransformer
- converts our classes to an interface+var declaration pair.