Skip to content

Conversation

@mauriciabad
Copy link
Contributor

Description

Documentation for the new ActionInputSchema utility type I proposed in withastro/astro#14698

I 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.

@netlify
Copy link

netlify bot commented Oct 31, 2025

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c23454c
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/691bdf8159903b0008853b6c
😎 Deploy Preview https://deploy-preview-12647--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Contributor

astrobot-houston commented Oct 31, 2025

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/reference/modules/astro-actions.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@sarah11918 sarah11918 added add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) labels Nov 3, 2025
<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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@sarah11918 sarah11918 added the minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah! label Nov 12, 2025
@sarah11918 sarah11918 added this to the 5.16.0 milestone Nov 12, 2025
@sarah11918
Copy link
Member

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!

Copy link
Member

@florian-lefebvre florian-lefebvre left a 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!

Copy link
Member

@sarah11918 sarah11918 left a 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).
Copy link
Member

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 FormData is best up there?

Just want to make sure that the docs are in sync with each other.

Copy link
Member

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 FormData object
  • the validator converts that to a different object shape
  • ActionInputSchema can 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.

Copy link
Contributor Author

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`.
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.".

Copy link
Contributor Author

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.

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Retrieve the expected **input type** of the action's validator.
* Retrieve the expected input type of the action's validator.

Copy link
Contributor Author

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.

@mauriciabad
Copy link
Contributor Author

Thanks everyone for the reviews, I added some comments and suggestions. Make any edits you want, for me all outcomes are okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) minor-release For the next minor release; in the milestone, "merge queue" when approved by Sarah!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants