From 8e17f5b74a117d0cb617fdab5179c1d63f7ee63a Mon Sep 17 00:00:00 2001 From: Bram Van der Sype Date: Sun, 22 Oct 2023 08:46:27 +0200 Subject: [PATCH 1/2] Having the generic type on `immer` makes you lose introspection in IDE's. --- docs/integrations/immer-middleware.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/integrations/immer-middleware.md b/docs/integrations/immer-middleware.md index c8c9c10bf1..7be1fe1d1e 100644 --- a/docs/integrations/immer-middleware.md +++ b/docs/integrations/immer-middleware.md @@ -34,8 +34,8 @@ type Actions = { decrement: (qty: number) => void } -export const useCountStore = create( - immer((set) => ({ +export const useCountStore = create()( + immer((set) => ({ count: 0, increment: (qty: number) => set((state) => { @@ -69,8 +69,8 @@ type Actions = { toggleTodo: (todoId: string) => void } -export const useTodoStore = create( - immer((set) => ({ +export const useTodoStore = create()( + immer((set) => ({ todos: { '82471c5f-4207-4b1d-abcb-b98547e01a3e': { id: '82471c5f-4207-4b1d-abcb-b98547e01a3e', From 920af4bf160e3c99b7928442aed1bb16f8dc916d Mon Sep 17 00:00:00 2001 From: Bram Van der Sype Date: Sun, 22 Oct 2023 08:48:39 +0200 Subject: [PATCH 2/2] Add note about parenthesis and link back to typescript guide. --- docs/guides/typescript.md | 2 +- docs/integrations/immer-middleware.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/guides/typescript.md b/docs/guides/typescript.md index 27becfa3da..33e9d28ac4 100644 --- a/docs/guides/typescript.md +++ b/docs/guides/typescript.md @@ -5,7 +5,7 @@ nav: 8 ## Basic usage -The difference when using TypeScript is that instead of writing `create(...)`, you have to write `create()(...)` (notice the extra parenthesis `()` too along with the type parameter) where `T` is the type of the state to annotate it. For example: +The difference when using TypeScript is that instead of writing `create(...)`, you have to write `create()(...)` (notice the extra parentheses `()` too along with the type parameter) where `T` is the type of the state to annotate it. For example: ```ts import { create } from 'zustand' diff --git a/docs/integrations/immer-middleware.md b/docs/integrations/immer-middleware.md index 7be1fe1d1e..5b00317373 100644 --- a/docs/integrations/immer-middleware.md +++ b/docs/integrations/immer-middleware.md @@ -19,6 +19,8 @@ npm install immer ## Usage +(Notice the extra parentheses after the type parameter as mentioned in the [Typescript Guide](../guides/typescript.md)). + Updating simple states ```ts