Skip to content

Commit

Permalink
fix(ts): reorder generic parameters of IProduce
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aleclarson committed Jan 12, 2019
1 parent ee8aac0 commit 05157af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/immer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ export interface IProduce {
* @param {Function} patchListener - optional function that will be called with all the patches produced here
* @returns {any} a new state, or the initial state if nothing was modified
*/
<T = any, D = Draft<T>, Return = void>(
<T = any, Return = void, D = Draft<T>>(
base: T,
recipe: (this: D, draft: D) => Return,
listener?: PatchListener
): Produced<D, Return>

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

0 comments on commit 05157af

Please sign in to comment.