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]: Passing Location objects into createMemoryRouter's initialEntries doesn't type-check #9470

Closed
ShaneDrury opened this issue Oct 16, 2022 · 3 comments · Fixed by #9498
Closed
Labels

Comments

@ShaneDrury
Copy link

What version of React Router are you using?

6.4.2

Steps to Reproduce

  • Use a Partial<Location> object in initialEntries when creating a memory router:
import { createMemoryRouter } from 'react-router-dom';
const router = createMemoryRouter([], {
  initialEntries: [{ pathname: '/foo', state: { myState: 'bar' } }],
});

Expected Behavior

The code type-checks and works as normal, where the state is accessible in the components with useLocation.

Actual Behavior

The code does not type-check but works as normal, where the state is accessible in the components with useLocation.
The type error is:

TS2322: Type '{ pathname: string; state: { myState: string; }; }' is not assignable to type 'string'.

This seems to be because initialEntries of createMemoryRouter is typed as string[] rather than InitialEntry[] which is what createMemoryHistory uses and initialEntries is passed on to.

@ShaneDrury ShaneDrury added the bug label Oct 16, 2022
@ShaneDrury
Copy link
Author

The documentation also seems to show the type as InitialEntry[].

@brophdawg11
Copy link
Contributor

Thanks! Just merged a fix for this in #9498, should be out in a 6.4.3-pre.1 hopefully today and then a stable 6.4.3 later this week or next

@ShaneDrury
Copy link
Author

Thanks a lot @brophdawg11! I appreciate it 👍

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

Successfully merging a pull request may close this issue.

2 participants