zundo
zundo copied to clipboard
TS Issue: Introduced in 1.2.2
This is a strange one because v1.2.2 doesn't seem to have many changes, but in my project, I have no type errors when using 1.2.1, when I upgrade to 1.2.2 (or higher) I'm getting the below error when trying to use the store.
src/store/index.ts:197:32 - error TS2345: Argument of type '(set: SetState<Partial<Pick<UndoStoreState, "undo" | "redo" | "clear"> & { getState: () => UndoStoreState; }>>, get: GetState<...>, api: StoreApi<...>) => Partial<...>' is not assignable to parameter of type 'StateCreator<Store, SetState<Store>> | StoreApi<Store>'.
Type '(set: SetState<Partial<Pick<UndoStoreState, "undo" | "redo" | "clear"> & { getState: () => UndoStoreState; }>>, get: GetState<...>, api: StoreApi<...>) => Partial<...>' is not assignable to type 'StateCreator<Store, SetState<Store>>'.
Types of parameters 'set' and 'set' are incompatible.
Types of parameters 'partial' and 'partial' are incompatible.
Type 'PartialState<Partial<Pick<UndoStoreState, "undo" | "redo" | "clear"> & { getState: () => UndoStoreState; }>, K1, K2, K3, K4>' is not assignable to type 'PartialState<Store, K1, K2, K3, K4>'.
Type 'Partial<Pick<UndoStoreState, "undo" | "redo" | "clear"> & { getState: () => UndoStoreState; }>' is not assignable to type 'PartialState<Store, K1, K2, K3, K4>'.
Type 'Partial<Pick<UndoStoreState, "undo" | "redo" | "clear"> & { getState: () => UndoStoreState; }>' is missing the following properties from type 'Store': addCameraAngle, setBatchId, setWizardText, setDidCatchError, and 81 more.
For now the easiest fix is just to use a @ts-ignore:
// @ts-ignore
const useStore = create<Store>(store)
Thanks for calling this out! I did some tests, but clearly was not thorough enough.
I do know the typing for zundo is pretty poor right now. Would you be able to share a larger code snippet or a code sandbox to help investigate the error? Do you have any initial ideas?
Reading the error message, it seems there are fields on your store that are not given default values perhaps?
In v1.2.2, I updated the developer dependencies, including the types dependency for lodash.isequal. I'm sure you already did this, but perhaps reinstalling your node modules would fix the TS issue?
I tried reinstalling modules, etc, that didn't seem to work. If this is specific to my project then there's no rush, I'll come back to this at some point and do some investigation :)
It may be specific to you're project, but I'm not sure. Would you be able to describe the context of your use case?
I haven't run into type issues yet so I'll plan on prioritizing other issues.
I hope to fix this in v2
Nearing the end of v2. Won't be fixing this issue.
The types for v2 are much better. Sorry for the hassle!