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

[TypeScript]: Type information in @types/redux-localstorage is incorrect or out of date #78

Open
hdpinto opened this issue Aug 10, 2017 · 2 comments

Comments

@hdpinto
Copy link

hdpinto commented Aug 10, 2017

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;
@ilennert
Copy link

ilennert commented Aug 20, 2017

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;

@makarkotlov
Copy link

Any updates? I'm still facing the issue
redux-localstorage: 0.4.1
@types/redux-localstorage: 1.0.8

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

No branches or pull requests

3 participants