-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Document new ActionInputSchema utility type
#12647
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
| <Since v="5.15.4" /> | ||
| </p> | ||
|
|
||
| A utility type that extracts the input's **zod schema type** from [an action handler](#defineaction). This can be useful if you need to reference an [action's validator]((#input-validator)) input type in your own type definitions. |
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.
| A utility type that extracts the input's **zod schema type** from [an action handler](#defineaction). This can be useful if you need to reference an [action's validator]((#input-validator)) input type in your own type definitions. | |
| A utility type that extracts the input's **zod schema type** from [an action handler](#defineaction). This can be useful if you need to reference an [action's validator](#input-validator) input type in your own type definitions. |
fix link syntax
|
Thanks for submitting this documentation with your feature @mauriciabad ! I will also ask @florian-lefebvre to check in on these docs after everything is resolved in the Astro feature PR to make sure what's here matches the decisions made over there! |
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.
Confirming we keep the name so docs can be reviewed!
Co-authored-by: Florian Lefebvre <[email protected]>
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.
Thanks for submitting docs to go with your feature, @mauriciabad ! I'll probably also need @ArmandPhilippot to help me with wording here because this is not my area of expertise and I do think we need to adjust the text here to match the Astro docs style.
I've left some comments/questions!
|
|
||
| A utility type that extracts the input's **zod schema type** from [an action handler](#defineaction). This can be useful if you need to reference an [action's validator](#input-validator) input type in your own type definitions. | ||
|
|
||
| Even if the action [accepts `form`](#accept-property), `ActionInputSchema` lets you get the input type as `object` rather than [`FormData`](https://developer.mozilla.org/docs/Web/API/FormData). |
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.
It feels like this wording needs checking against the wording at #accept-property (does that wording need any updating?) The docs for accept say:
When your action accepts form inputs, the z.object() validator will automatically parse FormData to a typed object. All Zod validators are supported to validate your inputs.
- is this still happening automatically?
- Does this happen in addition to you being able to get the input type as this new object?
- Do we need a link up there to this new entry to mention this option?
- It feels like maybe the link to
FormDatais best up there?
Just want to make sure that the docs are in sync with each other.
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 don't think this means the accept docs is outdated. What happens when using accept: "form" is:
- we define a Zod schema to validate the data
- the action sends a
FormDataobject - the validator converts that to a different object shape
ActionInputSchemacan be used to retrieve the type of that different object shape
So basically, I'd say ActionInputSchema doesn't care about the input shape. All it's doing is extracting the type of the final object.
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.
Actually this paragraph is not necessary because the returned type already documented above.
I added it thinking of possible doubts users would have, but it doesn't add any new info.
|
|
||
| Even if the action [accepts `form`](#accept-property), `ActionInputSchema` lets you get the input type as `object` rather than [`FormData`](https://developer.mozilla.org/docs/Web/API/FormData). | ||
|
|
||
| If the [`input` validator](#input-validator) is omitted, it returns `never`. |
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.
This says if input is not provided, "it" returns never. It's not clear to me what "it" is. (ActionInputSchema? Can it return never?) nor what never means in this context.
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.
it means the return type of the ActionInputSchema generic type. and never means the never TS type
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.
Yeah, this means that what we are trying to do will never happen, the type can't be resolved. In this context, if the input validator is not defined, then this utility type can't resolve the input type because it doesn't exist and will "fall back" to never.
When input is not defined, if you assign ActionInputSchema<typeof actions.contact> to a variable and try to assign a value, Typescript will complain because no value is valid. This is a way to detect something is wrong. Here what's wrong is that input is not defined.
So, I'm not sure "returns never" is clear enough for people less familiar with Typescript. Maybe we should instead say something like: "This utility type is only able to retrieve the type of an input when it is defined in your action.".
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 think it's important that the text contains the keyword never.
I wouldn't explain what never is, and if you think it's important, maybe instead link to some article or TS documentation.
| If the [`input` validator](#input-validator) is omitted, it returns `never`. | |
| Returns `never` when [`input` validator](#input-validator) is omitted. |
|
|
||
| The following example uses `ActionInputSchema` on an action named `contact` to: | ||
| * Retrieve the **zod schema type** for the input of the action. | ||
| * Retrieve the expected **input type** of the action's validator. |
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.
| * Retrieve the expected **input type** of the action's validator. | |
| * Retrieve the expected input type of the action's validator. |
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 think this bolds are important because they highlight the returned data. The sentence is very specific and the important info may get lose in all the words.
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>
|
Thanks everyone for the reviews, I added some comments and suggestions. Make any edits you want, for me all outcomes are okay. |
Description
Documentation for the new
ActionInputSchemautility type I proposed in withastro/astro#14698I put the latest version +1 patch in the
<Since>component, but I don't know the exact version yet.Feel free to change the text if is not clear :)
I also native Spanish, if you want me to translate it.