-
Notifications
You must be signed in to change notification settings - Fork 358
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
Overrides for TypeScript definition generation from JSG RTTI #133
Conversation
0c18f4e
to
45fd54a
Compare
45fd54a
to
aad867d
Compare
Looks good to me. I'll hold off giving it the stamp tho as it would be good to give it some time for others to review. Namely, it would be great to get some of the DO and R2 folks to review the overrides specific to those apis. |
Some DO things (I reviewed the generated output linked in the PR description).
|
aad867d
to
2cc857a
Compare
Done ✅ Updated the generated definitions gist.
We're working on including parameter names in a separate PR. 👍
Hmmm, I can only see one instance of |
5f1ddca
to
57290f6
Compare
@jasnell, @Frederik-Baetens approved the R2 bindings after pointing out |
0b4773c
to
46d8716
Compare
These allow the auto-generated TypeScript definitions to be customised, leading to higher fidelity types. - `JSG_(STRUCT_)TS_ROOT`: start visiting types for inclusion from this type - `JSG_(STRUCT_)TS_OVERRIDE`: customise the generated definition for this type by merging or replacing it with a partial TypeScript definition - `JSG_(STRUCT_)TS_DEFINE`: insert additional handwritten TypeScript next to the generated definition for this type
46d8716
to
9229a5e
Compare
Confirm that I've reviewed this on behalf of the R2 team. 👍 from me |
@mrbbot ... I'll land this now. If there is a corresponding internal PR, please be sure to get that landed also :-) |
Hey! 👋 This is a follow-up PR to cloudflare/workers-types#113, enabling auto-generated TypeScript definitions to be customised with "overrides". These are based on how
autodecl
used to work, however overrides are now written alongside the original C++ definitions using macros. This should mean overrides don't get out-of-sync with the original definitions.In particular, 6 new macros have been added:
JSG_(STRUCT_)TS_ROOT
: start visiting types for inclusion from this typeJSG_(STRUCT_)TS_OVERRIDE
: customise the generated definition for this type by merging or replacing it with a partial TypeScript definitionJSG_(STRUCT_)TS_DEFINE
: insert additional handwritten TypeScript next to the generated definition for this typeSee the documentation in
src/workerd/jsg/jsg.h
for more explanation on each.Arguments to these macros are stored verbatim in the encoded RTTI Cap'n Proto file, and are parsed using the TypeScript Compiler API in the generation scripts. This approach means any TypeScript is valid in overrides (e.g. we can now use the
&
type operator).I've tested this PR against the internal test suite and no additional changes were required for it to pass.
A copy of the generated types can be found here.
This PR also fixes a number of
workers-types
issues related to incorrect overrides:fetch()
request parameter's type is not correct workers-types#277KVNamespaceListResult
more specific types workers-types#264(value: unknown) => void
tosetTimeout
workers-types#239Notably, #294 has not yet been fixed.
Closes cloudflare/workers-types#304.