Skip to content
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

Make formAction return inferrable #123

Open
gustavoguichard opened this issue Dec 7, 2022 · 1 comment
Open

Make formAction return inferrable #123

gustavoguichard opened this issue Dec 7, 2022 · 1 comment
Assignees

Comments

@gustavoguichard
Copy link
Contributor

gustavoguichard commented Dec 7, 2022

Whenever we return the formAction in an action:

export async function action({ request }: ActionArgs) {
  return formAction( // ...)
}

export default function() {
  const actionData = useActionData<typeof action>()
  //         ^? any
}

The useActionData loses the inference - it will be inferred as any.

It'd be cool that it would infer the TypedResponse for us.
The inferred type should probably be a union of:

{ errors: FormErrors<SchemaType>, values: FormValues<SchemaType> } | UnpackData<typeof mutation>

Things to consider:

  • If we use a custom json in createFormAction we should be using the return of that given function
  • If we set a successPath in the formAction the return type of the mutation should not be considered:
{ errors: FormErrors<SchemaType>, values: FormValues<SchemaType> }
@gustavoguichard
Copy link
Contributor Author

I'd be happy to pair on this one ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants