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

[Bug]: Type of loaderData wrong when returning redirect in the loader (action as well) #12335

Open
mrNuTz opened this issue Nov 21, 2024 · 1 comment
Labels

Comments

@mrNuTz
Copy link

mrNuTz commented Nov 21, 2024

What version of React Router are you using?

7

Steps to Reproduce

export const loader = () => {
  if (Math.random() < 0.5) {
    return redirect('/')
  }
  return {some: 'data'}
}

export default function Home() {
  const data = userLoaderData<typeof loader>()
  return <>{data.some}</> // ERROR: some not in type {headers: ...}
}

Expected Behavior

some should be defined on the loaderData

Actual Behavior

there is a typescript error

@mrNuTz mrNuTz added the bug label Nov 21, 2024
@Moonflower-labs
Copy link

Hi, I had a similar issue. If you throw the redirect instead of returning it, the typescript error should go away.

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

No branches or pull requests

2 participants