Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Relax types for
persist
middleware (#2332)
Right now, we're requiring new `StateStorage` implementations to forcefully return `void` from inside `setItem` and `removeItem`. When using a library that returns the set value for `setItem` or `removeItem`, therefore returning a `string`, it causes Typescript to fail, requiring some weird workarounds. For example, when using `localforage` (https://github.com/localForage/localForage) one needs to do what we describe below. Notice the `void` keyword. ```typescript const storage: StateStorage = { ...localForage, setItem: void localForage.setItem.bind(localForage) } ``` Another, longer, alternative is ```typescript const storage: StateStorage = { ...localForage, // Curly braces are required because we need to "return `void`" setItem: (name, value) => { localStorage.setItem(name, value) } } ``` By changing the type implementation to ignore types - using unknown - we can simply use `localforage` - and similar libraries - as if we were using `window.localStorage`
- Loading branch information