sergiodxa / remix-utils

A set of utility functions and types to use with Remix.run
https://sergiodxa.github.io/remix-utils/
MIT License
2.12k stars 118 forks source link

Cast redirectBack return value to TypedResponse<never> #303

Closed balzdur closed 8 months ago

balzdur commented 9 months ago

Context

ATM, the current return type of redirectBack is Response, making type inference messy when doing :

const fetcher = useFetcher<typeof action>();

I changed the return type based on the one of redirect from Remix code

Example :

With my current code base were I spotted the issue

Before

image

After

image

This happen when you mix redirectBack with other return statements, like the following

export async function action({ request }: ActionFunctionArgs) {
  const formData = await request.formData();
  const submission = parse(formData);

  if (!submission.isValid) {
    return json(submission);
  }

 return redirectBack(request, {
      fallback: getRoute('/scenarios/:scenarioId', {
        scenarioId: fromUUID(submission.value.scenarioId),
      }),
    });
}