feat: Add ActionInputSchema utility type
#14698
Open
+27
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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