History v5 types error + back and forward actions are not exported
MustonenMishka opened this issue · 7 comments
- goBack and goForward methods are no longer exist in history v5 types. Build process is crashing
- new back and forward actions are not exported from index.ts
I think the possible solution is to leave history v4 behind and fully switch to v5. It will get rid of type errors and use appropriate methods
Getting these errors too, currently transitioning from react-router v5 to v6 and it's tripping me up. At present, my app won't compile, but it's not clear if it's from this specific issue or from something else.
Update- the issue blocking actual building of the app was something else, but the warning persists in an otherwise successful app execution now that I'm fully on v6 for react-router-dom
. I'll need to give the below suggestion a shot in the meantime.
I am seeing the same incompatibility with this and the latest history
v5.3.0.
> tsc --noEmit
node_modules/redux-first-history/src/actions.ts:48:71 - error TS2339: Property 'goBack' does not exist on type 'History'.
48 export const goBack: () => CallHistoryMethodAction<Parameters<History['goBack']>> =
node_modules/redux-first-history/src/actions.ts:50:74 - error TS2339: Property 'goForward' does not exist on type 'History'.
50 export const goForward: () => CallHistoryMethodAction<Parameters<History['goForward']>> =
I think it was missed because this project's dev dependency is still on history v4 when these properties still existed. It was an undocumented breaking change in history v4 -> v5, see remix-run/history#811
I will be the first to admit I'm not familiar with the best way to solve this issue, nor have I made many contributions to package development- but if we know it'll have either back
OR goBack
, and forward
OR goForward
, could do we an approach that uses one or the other based on what's available? The change mentioned by baileyandy states that they are functionally equivalent, it's just the name that's changed.
If that isn't possible, then the original suggestion to abandon history v4 altogether- potentially with a minor, or even major, version change- is probably the next best option here. It feels like potential overkill for just this issue, so if we have an easier way to solve it that would probably be preferred, but... it's gotta happen at some point anyway, right?
as a workaround for the compilation error you can add this somewhere in your code:
declare module 'history' {
interface History {
goBack(): void;
goForward(): void;
}
}
and then just use history.back()
/ history.forward()
I have placed the following file history.d.ts
under @types
directory.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Histroy from 'history';
declare module 'history' {
interface History{
goBack(): void;
goForward(): void;
}
}