-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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]: Typescript 4.9.x error when using #10505
Comments
The |
In
As you stated the To type is imported from
So for me it's missing an overload here, on line 150 of
And it should become:
|
@timdorr to date |
There is the overload of react-router/packages/react-router/lib/hooks.tsx Lines 153 to 156 in 0f2b167
|
And just confirming that this works in TS 4.9 (as well as other versions): |
Let's assume that we are using Without workarounds like mentioned above:
I think its not possible to satisfy TS cause basically we end up with something like this |
Albeit ugly, it does the job. I wonder if this overload design was used because this way development was easier. From the user of the library perspective, it seems as if having a type that accepts |
The overload doesn't accept the |
Mainly to avoid the tricky workaround for the ReactRouterDom#navigate overloading. See remix-run/react-router#10505 (comment)
What version of React Router are you using?
6.11
Steps to Reproduce
Starting from
<RouterProvider>
.Import
useNavigate
from "react-router-dom".Paste this three functions on line 22 under App component.
Open a new terminal and run
npm run build
to runtsc
Expected Behavior
react-router ts files compile with no error
Actual Behavior
According to the documentation,
navigate
accepts both numbers or string, in order of going next/back in the historynavigate(-1)
or to reach the targeted routenavigate('/pages')
.When used alone
navigate
works pretty well, but not when it's wrapped in an other function.The text was updated successfully, but these errors were encountered: