Skip to content

Commit

Permalink
fix(flow): added types for produceWithPatches
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jul 24, 2020
2 parents e8639dc + 35e5b11 commit b355838
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/types/index.js.flow
Expand Up @@ -39,9 +39,33 @@ interface IProduce {
): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S;
}

interface IProduceWithPatches {
/**
* Like `produce`, but instead of just returning the new state,
* a tuple is returned with [nextState, patches, inversePatches]
*
* Like produce, this function supports currying
*/
<S: Base>(
currentState: S,
recipe: (draftState: S) => S | void
): [S, Patch[], Patch[]];
// curried invocations with inital state
<S: Base, A = void, B = void, C = void>(
recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void,
initialState: S
): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];
// curried invocations without inital state
<S: Base, A = void, B = void, C = void>(
recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void
): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];
}

declare export var produce: IProduce
declare export default IProduce

declare export var produceWithPatches: IProduceWithPatches

declare export var nothing: typeof undefined

declare export var immerable: Symbol
Expand Down

0 comments on commit b355838

Please sign in to comment.