Skip to content

Conversation

@mauriciabad
Copy link
Contributor

@mauriciabad mauriciabad commented Oct 31, 2025

Changes

Adds the utility type ActionInputSchema that returns the type of the zod schema used in defineAction({ 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:

import { type ActionInputSchema, defineAction } from 'astro:actions';
import { z } from 'astro/zod';

const action = defineAction({
  accept: 'form',
  input: z.object({ name: z.string() }),
  handler: ({ name }) => ({ message: `Welcome, ${name}!` }),
});

type Schema = ActionInputSchema<typeof action>; 
// typeof z.object({ name: z.string() })

type Input = z.input<Schema>;
// { name: string }

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

  1. If the input validator is omitted, it returns never. Do you think it's fine? Or it should return something else, like undefined?

  2. Initially, I was going to create the type ActionInput directly, to avoid having to do z.input<ActionInputSchema<typeof action>>. But I thought the name would be confusing because when the action accepts a form, the input is actually a FormData, 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 type ActionInputObject or 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

@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2025

🦋 Changeset detected

Latest commit: 398c61c

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Oct 31, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

📝 Changeset Validation Results

Changeset validation failed

Issues Found:

.changeset/poor-loops-boil.md

Issue with: 'change type: patch'

❌ The provided changeset description implies a 'minor' change type as it introduces a new feature.

💡 Change the type to 'minor' for better alignment with the described feature.

Issue with: 'Adds the ActionInputSchema utility type to infer an action's input zod schema.'

❌ The description does not fully elaborate on the usage and benefits of the added feature.

💡 Extend the description to include more context about the change and its use cases, as shown in the provided example snippet.


📖 See Astro's changeset guide for details.

@mauriciabad mauriciabad changed the title feat: Add ActionInputSchema utility type feat: Add ActionInputSchema utility type Oct 31, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 31, 2025

CodSpeed Performance Report

Merging #14698 will not alter performance

Comparing mauriciabad:patch-1 (398c61c) with main (3d55c5d)

Summary

✅ 6 untouched

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

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant