[TypeScript]: Type information in @types/redux-localstorage is incorrect or out of date
hdpinto opened this issue · 2 comments
When attempting to use persistState( ... )
type definition is incorrect, typing information is possibly out of date.
Sample code throwing error:
import * as persistState from "redux-localstorage";
const enhancer = compose(
persistState([
"pathOne",
"pathTwo",
], { key: "example-key" }),
);
Code works fine without @types/redux-localstorage
installed, this is the current workaround.
See index.d.ts in @types/redux-localstorage
below:
// Type definitions for redux-localstorage 1.0
// Project: https://github.com/elgerlambert/redux-localstorage
// Definitions by: Karol Janyst <https://github.com/LKay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as Redux from "redux";
export interface ActionTypes {
INIT: string;
}
export type AdapterCallback = <A>(err?: any, result?: A) => void;
export interface StorageAdapter<A> {
0: A;
put(key: string, value: any, callback: AdapterCallback): void;
get(key: string, callback: AdapterCallback): void;
del(key: string, callback: AdapterCallback): void;
}
export type StorageAdapterCreator<A> = (storage: A) => StorageAdapter<A>;
export interface StorageAdapterEnhancer {}
export function mergePersistedState(merge?: <A1, A2>(initialState: A1, persistentState: A2) => A1 & A2): <A>(next: Redux.Reducer<A>) => Redux.Reducer<A>;
export default function persistState<A>(storage?: StorageAdapter<A>, key?: string, callback?: Function): Redux.GenericStoreEnhancer;
export const actionTypes: ActionTypes;
This is very important if you turn on "strict": true, in the tsconfig. I've written my own '.d.ts' file so I can get Webpack to create output. Until I come up with some sort of fix I'm done... I just put it in the node_modules/@types/redux-localstorage
and name it "index.d.ts" and the transpiler has no trouble finding it. Here's the file (I only needed the 'persistState' function. Notice, it is completely different from the above 'persistState' function type definition.
// Type definitions for redux-localstorage persistState, until a better solution becomes available
import * as Redux from "redux";
export interface ConfigRS {
key: string;
merge?: any;
slicer?: any;
serialize: (value: any, replacer?: (key: string, value: any) => any, space?: string | number) => string,
deserialize: (text: string, reviver?: (key: any, value: any) => any) => any
}
export default function persistState(paths: string | string[], config: ConfigRS): Redux.GenericStoreEnhancer;
Any updates? I'm still facing the issue
redux-localstorage: 0.4.1
@types/redux-localstorage: 1.0.8