chrisvander / zustand-computed

A Zustand middleware to create computed states.
MIT License
87 stars 10 forks source link

fix: updated setWithComputed by adding the third optional action parameter #13

Closed DanDroryAu closed 12 months ago

DanDroryAu commented 1 year ago

Issue: In order to use the redux devtools propperly you have to set the third optional action parameter. This allows you to track the action inside of the redux dev tools.

This is currently not passed through and in turn makes the dev tools register the action as 'anonymous'

Screenshot 2023-11-02 at 2 17 42 pm

Please look at this comment by a zustand contributor as to why I've added this field.

https://github.com/pmndrs/zustand/issues/705#issuecomment-992976936

DanDroryAu commented 12 months ago

Hey @chrisvander, I've also noticed my types were wrong. This morning typescript casted them correctly. I've got to update the set functions arguments to accept an unknown[] rest type.

DanDroryAu commented 12 months ago

@chrisvander, You just pushed your fix before I amended my commit.

Different workflow, my apologies.

I've simplified it by making the rest params of type [], which is the same type that the offical middleware uses. Check immer.ts middleware. It's rest type gets cast to [].

Let me know if you want me to revert to your fix instead.

chrisvander commented 12 months ago

Oh, interesting! I would prefer reverting to my fix because I don't think that the set() call passes the linter check without the adjusted type I put in. Is [] the same as using unknown[]?

DanDroryAu commented 12 months ago

Oh, interesting! I would prefer reverting to my fix because I don't think that the set() call passes the linter check without the adjusted type I put in. Is [] the same as using unknown[]?

TBH I've never seen that type before. I just pulled the zustand repo and checked why the immer.ts file doesn't throw a type error on the ...a rest prop. The props type was [] when I inspected it. (And it did pass the linter after that)

I was tinkering with setting the type of it myself but wasn't well versed enough in the typescript setup from Zustand.