Skip to content

Commit 05157af

Browse files
committed
fix(ts): reorder generic parameters of IProduce
This makes the different call signatures of `produce` have a similar order of generic parameters when possible. Before: produce<Base, [number, string]>((draft, num, str) => {}) // no default produce<Base, Draft<Base>, [number, string]>((draft, num, str) => {}, defaultValue) After: produce<Base, [number, string]>((draft, num, str) => {}) // no default produce<Base, [number, string]>((draft, num, str) => {}, defaultValue) As you can see, the draft type is no longer the 2nd generic parameter of curried producers with a default value, which is just like the call signature for curried producers without a default value. This also moves the `D` generic parameter of `produce(base, recipe)` to the end, so you can specify the `Return` parameter easier.
1 parent ee8aac0 commit 05157af

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/immer.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ export interface IProduce {
9797
* @param {Function} patchListener - optional function that will be called with all the patches produced here
9898
* @returns {any} a new state, or the initial state if nothing was modified
9999
*/
100-
<T = any, D = Draft<T>, Return = void>(
100+
<T = any, Return = void, D = Draft<T>>(
101101
base: T,
102102
recipe: (this: D, draft: D) => Return,
103103
listener?: PatchListener
104104
): Produced<D, Return>
105105

106106
/** Curried producer with a default value */
107-
<T = any, D = Draft<T>, Rest extends any[] = [], Return = void>(
107+
<T = any, Rest extends any[] = [], Return = void, D = Draft<T>>(
108108
recipe: (this: D, draft: D, ...rest: Rest) => Return,
109109
defaultBase: T
110110
): (base: Immutable<D> | undefined, ...rest: Rest) => Produced<D, Return>

0 commit comments

Comments
 (0)