zundo icon indicating copy to clipboard operation
zundo copied to clipboard

TS Issue: Introduced in 1.2.2

Open funwithtriangles opened this issue 4 years ago • 6 comments

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)

funwithtriangles avatar Oct 25 '21 10:10 funwithtriangles

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?

charkour avatar Oct 25 '21 11:10 charkour

Reading the error message, it seems there are fields on your store that are not given default values perhaps?

charkour avatar Oct 25 '21 11:10 charkour

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?

charkour avatar Oct 25 '21 11:10 charkour

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 :)

funwithtriangles avatar Oct 25 '21 15:10 funwithtriangles

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.

charkour avatar Oct 25 '21 22:10 charkour

I hope to fix this in v2

charkour avatar Jan 08 '22 17:01 charkour

Nearing the end of v2. Won't be fixing this issue.

The types for v2 are much better. Sorry for the hassle!

charkour avatar Aug 19 '22 04:08 charkour