diff --git a/src/computed.ts b/src/computed.ts index 2848fbb..8013e77 100644 --- a/src/computed.ts +++ b/src/computed.ts @@ -13,37 +13,35 @@ export type ComputedStateCreator = < Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = [], >( + compute: (state: T) => A, f: StateCreator, + opts?: ComputedStateOpts, +) => StateCreator + +type ComputedStateImpl = ( compute: (state: T) => A, + f: StateCreator, opts?: ComputedStateOpts, -) => StateCreator +) => StateCreator -type Cast = T extends U ? T : U type Write = Omit & U type StoreCompute = S extends { getState: () => infer T } - ? Omit, "setState"> + ? Omit>, "setState" | "getInitialState"> : never -type WithCompute = Write> declare module "zustand" { interface StoreMutators { - "chrisvander/zustand-computed": WithCompute, A> + "chrisvander/zustand-computed": Write> } } -type ComputedStateImpl = ( - f: StateCreator, - compute: (state: T) => A, - opts?: ComputedStateOpts, -) => StateCreator - type SetStateWithArgs = Parameters>[0] extends (...args: infer U) => void ? (...args: [...U, ...unknown[]]) => void : never -const computedImpl: ComputedStateImpl = (f, compute, opts) => { +const computedImpl: ComputedStateImpl = (compute, f, opts) => { // set of keys that have been accessed in any compute call const trackedSelectors = new Set() return (set, get, api) => {