rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.95k stars 866 forks source link

Typescript error #841

Open Venryx opened 6 years ago

Venryx commented 6 years ago

Typescript error message:

node_modules/redux-persist/src/index.d.ts(352,93): error TS2314: Generic type 'Reducer' requires 1 type argument(s).
node_modules/redux-persist/src/index.d.ts(352,109): error TS2314: Generic type 'Reducer' requires 1 type argument(s).

This is caused because between version 5.9.1 and 5.10.0, the index.d.ts contents for the persistReducer file in redux-persist changed from:

declare module "redux-persist/es/persistReducer" {
    [...]
    export function persistReducer<S, A>(config: PersistConfig, baseReducer: BaseReducer<S, A>): (s: S, a: A) => S & PersistPartial;
}

To:

declare module "redux-persist/es/persistReducer" {
    [...]
    export function persistReducer<S, A extends Action>(config: PersistConfig, baseReducer: Reducer<S, A>): Reducer<S & PersistPartial, A>;
}

I don't know which is "correct", but I know that the new version is causing typescript errors (since Typescript says Reducer only accepts one type argument), and that a semver minor update shouldn't be introducing new errors.

Note that I'm using the same redux version in both projects, v3.7.2. (error showed in new project with redux-persist 5.10.0, but not in the one with 5.9.1, so I investigated the cause)

darewreck54 commented 6 years ago

I'm experiencing the same issue. I just installed 5.10.0, and getting the same error but i'm using "redux": "3.7.2" not the "4.0.0". When I downgrade to 5.9.1, it seems to address the issue. Perhaps the 5.10 is tied to a specific redux version?

Venryx commented 6 years ago

For now, I'm brute-forcing a fix by just manually changing that line in the node_modules/.../index.d.ts file to:

export function persistReducer<S, A extends Action>(config: PersistConfig, baseReducer: Reducer<S>): Reducer<S & PersistPartial>;

Not a real solution since manual node_modules changes can't be cleanly tracked by git, but a stop-gap fix for the moment.

ethanroday commented 6 years ago

I believe @darewreck54 is correct. The type definitions for 5.10.0 assume Redux ^4.0.0, in which the type signature for reducers changed, but that is not reflected anywhere in package.json. @rt2zz, Not sure if the correct course of action is to change the peer dependency version or to bump a major version here, but I think some check does need to be put in place. @Venryx, you can also change the redux-persist version in your project's package.json to 5.9.1 instead of ^5.X.X to enforce the correct version until this is resolved.

LucianDavies commented 5 years ago

was this ever fixed ?

Yhozen commented 5 years ago

Any updates?

feiyl commented 5 years ago

Any updates?

damathryx commented 5 years ago

any update on this

tomaszs commented 4 years ago

2020 here