-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: Add ActionInputSchema utility type
#14698
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
Conversation
🦋 Changeset detectedLatest commit: 67c9bb5 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 Changeset Validation Results❌ Changeset validation failed Issues Found:
|
ActionInputSchema utility type
CodSpeed Performance ReportMerging #14698 will not alter performanceComparing Summary
|
florian-lefebvre
left a comment
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.
Hi, thanks for opening a PR! I think it's a nice addition, a few comments:
- I wonder if it should be named something else, eg.
InferActionInputSchema<T>? Would be nice to check if we have other cases like this in Astro (I don't think we do) and otherwise what other tools use. I'm suggesting "infer" because of zod but really it could be anything - Can you add type tests for this? In
packages/astro/test/types/
|
Just noting that I will wait to review the docs until @florian-lefebvre 's naming issue has been addressed! |
|
@florian-lefebvre Thanks for taking a look.
|
|
Okay makes sense! Then let's keep the currrent naming 👍 (and a single new type helper). FYI we plan to include these changes in 5.16, to be released next week |
|
I added JSDoc; if you don't like it, remove it. I also added the tests. |
florian-lefebvre
left a comment
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.
Approving in terms of code! @sarah11918 this is ready for your review
sarah11918
left a comment
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.
Just a quick note from me re: introducing the code sample!
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Changes
Adds the utility type
ActionInputSchemathat returns the type of the zod schema used indefineAction({ input: z.object(...) }).This is incredibly useful for creating abstractions that use actions.
The main use will be getting the action input type when the action has
accept: 'form'.Example usage:
Since it's quite hard to pull off by a non-typescript fluent dev, I suggest including it along the other action utility types.
Decisions to be made
If the
inputvalidator is omitted, it returnsnever. Do you think it's fine? Or it should return something else, likeundefined?Initially, I was going to create the type
ActionInputdirectly, to avoid having to doz.input<ActionInputSchema<typeof action>>. But I thought the name would be confusing because when the action accepts aform, the input is actually aFormData, not a JS object. And returning the schema seems more versatile. Let me know if you think it would be valuable to also add a utility typeActionInputObjector something like that.Testing
No tests needed because it's a type.
Docs
The astro-actions page should be updated. I opened a PR with the documentation: withastro/docs#12647
/cc @withastro/maintainers-docs