mutative icon indicating copy to clipboard operation
mutative copied to clipboard

TS4058 Return type of exported function has or is using name DraftedObject from external module

Open wenerme opened this issue 4 months ago • 3 comments

zustand with mutative

Image

I don't know how to workaround this, mutative only export Draft type, the DraftedObject is internal type. using TS 5.9.2, WebStorm

wenerme avatar Aug 21 '25 18:08 wenerme

I will try to reproduce this TS type issue later.

unadlib avatar Aug 22 '25 11:08 unadlib

@wenerme , I'm not sure if the mutative() you're referring to is the one from zustand-mutative. In any case, it works fine with TypeScript v5.9.2.

import { create } from "zustand";
import { mutative } from "zustand-mutative";

type State = {
  count: number;
};

type Actions = {
  increment: (qty: number) => void;
  decrement: (qty: number) => void;
};

export const useCountStore = create<State & Actions>()(
  mutative((set) => ({
    count: 0,
    increment: (qty: number) =>
      set((state) => {
        state.count += qty;
      }),
    decrement: (qty: number) =>
      set((state) => {
        state.count -= qty;
      }),
  }))
);

unadlib avatar Aug 22 '25 13:08 unadlib

thanks, yes, from zustand-mutative, I'll try reproduce with a minimal repo.

wenerme avatar Aug 22 '25 17:08 wenerme