zustand-store-addons icon indicating copy to clipboard operation
zustand-store-addons copied to clipboard

Type error when using immer middleware

Open GoodbyeNJN opened this issue 2 years ago • 1 comments

Example code:

import create from "zustand-store-addons";

interface Store {
    value: number;
    increase: () => void;
}

export const useStore = create<Store>(
    (set, get) => ({
        value: 0,

        increase: () => {
            set(state => { // Report error at this line
                ^^^^^^^^^^
                state.value++;
            });
        },
    }),
    { middleware: [immer] },
);

Error info:

Argument of type '(state: Store) => void' is not assignable to parameter of type 'PartialState<Store>'.
  Type '(state: Store) => void' is not assignable to type '(state: Store) => Partial<Store>'.
    Type 'void' is not assignable to type 'Partial<Store>'.ts(2345)

It looks like the original action type is not compatible with the action type after using Immer middleware.

GoodbyeNJN avatar Sep 07 '22 18:09 GoodbyeNJN

@GoodbyeNJN is this still an issue? @Diablow is there anything we can help with or provide to get this resolved?

joeyfigaro avatar Mar 02 '23 16:03 joeyfigaro