diff --git a/website/docs/typescript.mdx b/website/docs/typescript.mdx index 73d227d3..deca9fb8 100644 --- a/website/docs/typescript.mdx +++ b/website/docs/typescript.mdx @@ -10,7 +10,8 @@ sidebar_label: TypeScript / Flow data-ea-type="image" className="horizontal bordered" > -
+ +
egghead.io lesson 12: Immer + TypeScript @@ -181,7 +182,7 @@ const toggler = produce(draft => { // typeof toggler = (state: Todo) => Todo ``` -However, in case the curried producer is defined with an initial state, Immer can infer the state type from the initial state, so in that case the generic doesn't need to be specified either: +Pass an initial state as the second argument to `produce` to let Immer infer the state type. The curried producer uses this state as its base when called without an argument or with `undefined`. A default value on the recipe's draft parameter is applied inside the recipe, after Immer has chosen the base, so it does not provide a default draft. ```typescript const state0: Todo = { @@ -194,7 +195,8 @@ const toggler = produce(draft => { draft.done = !draft.done }, state0) -// typeof toggler = (state: Todo) => Todo +// typeof toggler = (state?: Todo) => Todo +const next = toggler() // {title: "test", done: true} ``` In case the toggler has no initial state, and it has curried arguments, and you set the state generic explicitly, then type of any additional arguments should be defined explicitly as a tuple type as well: