【发布时间】:2022-11-06 08:40:01
【问题描述】:
我正在尝试使用 zustand 的 devtools 功能。我也在使用打字稿。当我将商店传递给 devtools 时,我的整个商店代码会抛出错误:Argument of type 'StateCreator<Store, [], [["zustand/devtools", never]], Store>' is not assignable to parameter of type 'StateCreator<Store, [], [], Store>'.
这是我的商店代码:
const useUserStore = create<Store>(devtools((set) => ({
token: "",
isLogged: false,
loginUser: (jwtToken: string) => {
set((state) => ({
...state,
token: jwtToken,
isLogged: true,
}));
},
logoutUser: () => {
set((state) => ({
...state,
token: "",
isLogged: false,
}));
},
})));
这是商店类型:
export type Store = {
token: string;
isLogged: boolean;
loginUser: (jwtToken: string) => void;
logoutUser: () => void;
};
请指导我如何解决此错误。
【问题讨论】:
-
相关:zustand#1013
标签: typescript zustand