Skip to content
Myr

fix(ts): reorder generic parameters of IProduce

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by aleclarson · committed by aleclarson · parent ee8aac0 · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:src/immer.d.ts+2 added-2 removed
95 unmodified lines
96 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified97 * @param {Function} patchListener - optional function that will be called with all the patches produced here98 * @returns {any} a new state, or the initial state if nothing was modified99 */100 <T = any, D = Draft<T>, Return = void>(100 <T = any, Return = void, D = Draft<T>>(101 base: T,102 recipe: (this: D, draft: D) => Return,103 listener?: PatchListener104 ): Produced<D, Return>105106 /** 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>>(108 recipe: (this: D, draft: D, ...rest: Rest) => Return,109 defaultBase: T110 ): (base: Immutable<D> | undefined, ...rest: Rest) => Produced<D, Return>111
103 unmodified lines