Skip to content

Missing type inference using TypeScript and Immer following example from Readme #2783

Closed Answered by dbritto-dev
Duckling92 asked this question in Bug report
Discussion options

You must be logged in to vote

@Duckling92 you are using produce from immer directly so you need to take care of typing produce, that's not zustand issue

import { produce } from 'immer'
import { create } from 'zustand'

interface MyStore {
  aNumber: number
  setNumber: () => void
}
const useStore = create<MyStore>()((set, get) => ({
  aNumber: 0,
  setNumber: () => set(
    produce<ReturnType<typeof get>>((state) => {
      state.aNumber = "not a number"
    }),
  ),
}))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Duckling92
Comment options

Answer selected by dbritto-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants