Skip to content

Commit fa5bf5d

Browse files
committed
fix(ts): produce function
Fixes #270
1 parent 025841e commit fa5bf5d

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/immer.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,26 @@ export interface IProduce {
7373
* @param {Function} patchListener - optional function that will be called with all the patches produced here
7474
* @returns {any} a new state, or the initial state if nothing was modified
7575
*/
76-
<S = any, R = never>(
77-
currentState: S,
78-
recipe: (this: Draft<S>, draft: Draft<S>) => void | R,
76+
<State, Result = any>(
77+
currentState: State,
78+
recipe: (this: Draft<State>, draft: Draft<State>) => Result,
7979
listener?: PatchListener
80-
): R
80+
): void extends Result ? State : Result
8181

8282
/** Curried producer with an initial state */
83-
<S = any, R = never>(
84-
recipe: (this: Draft<S>, draft: Draft<S>) => void | R,
85-
defaultBase: S
86-
): (base: S | undefined) => R
83+
<State, Result = any>(
84+
recipe: (this: Draft<State>, draft: Draft<State>) => void | Result,
85+
defaultBase: State
86+
): (base: State | undefined) => void extends Result ? State : Result
8787

8888
/** Curried producer with no initial state */
89-
<S = any, R = never, Args extends any[] = any[]>(
89+
<State, Result = any, Args extends any[] = any[]>(
9090
recipe: (
91-
this: Draft<S>,
92-
draft: Draft<S>,
91+
this: Draft<State>,
92+
draft: Draft<State>,
9393
...extraArgs: Args
94-
) => void | R
95-
): (base: S, ...extraArgs: Args) => R
94+
) => void | Result
95+
): (base: State, ...extraArgs: Args) => void extends Result ? State : Result
9696
}
9797

9898
export const produce: IProduce

0 commit comments

Comments
 (0)