Skip to content

Commit b355838

Browse files
authored
fix(flow): added types for produceWithPatches
2 parents e8639dc + 35e5b11 commit b355838

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/types/index.js.flow

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,33 @@ interface IProduce {
3939
): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S;
4040
}
4141

42+
interface IProduceWithPatches {
43+
/**
44+
* Like `produce`, but instead of just returning the new state,
45+
* a tuple is returned with [nextState, patches, inversePatches]
46+
*
47+
* Like produce, this function supports currying
48+
*/
49+
<S: Base>(
50+
currentState: S,
51+
recipe: (draftState: S) => S | void
52+
): [S, Patch[], Patch[]];
53+
// curried invocations with inital state
54+
<S: Base, A = void, B = void, C = void>(
55+
recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void,
56+
initialState: S
57+
): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];
58+
// curried invocations without inital state
59+
<S: Base, A = void, B = void, C = void>(
60+
recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void
61+
): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]];
62+
}
63+
4264
declare export var produce: IProduce
4365
declare export default IProduce
4466

67+
declare export var produceWithPatches: IProduceWithPatches
68+
4569
declare export var nothing: typeof undefined
4670

4771
declare export var immerable: Symbol

0 commit comments

Comments
 (0)