amend flow definitions to include return types from recipe
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jack Zhao · committed by Jack Zhao · parent 38ebb75 · Browse files · 2 files·+24 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+24 added−15 removed
- tests:+13 added−4 removed
- other:+11 added−11 removed
Provenance
- Commit
186c61c- Tree
0333095- Author
Jack Zhao <yzhao@grailbio.com>- Committer
Jack Zhao <yzhao@grailbio.com>- Parent
38ebb75
2 files changed+24 added−15 removed
modified:__tests__/flow/flow.js.flow+13 added-4 removed
12 unmodified lines13 })14 15 console.log(result.x)16 17-const f2 = produce(draft => {})17+const result2 = produce({x: 3}, draft => {18+ return {x: 4};19+})20+21+console.log(result2.x)22+23+const f = produce((draft): ({x: number}) => { return {x: 4}; });24+f({x: 3});25+26+const f2 = produce((draft): void => {})27 f2({x: 3})28 29 // $ExpectError30 setAutoFreeze(3)11 unmodified lines42 produce({x: 3}, [])43 44 {45 // curried & initial arg37- const f = produce((state, increment: number) => {46+ const f = produce((state, increment: number): void => {47 state.x += increment48 }, { x: 3})49 50 // $ExpectError Too few arguments8 unmodified lines59 }60 61 {62 // curried f & no initial arg54- const f2 = produce((state: {x:number}, increment: number) => {63+ const f2 = produce((state: {x:number}, increment: number): void => {64 state.x += increment65 })66 67 f2({x : 5}, 3)68 69 // $ExpectError70 f2(undefined, 3)62-}71+}modified:src/immer.js.flow+11 added-11 removed
13 unmodified lines14 * @returns The next state: a new state, or the current state if nothing was modified15 */16 declare export default function produce<S>(17 currentState: S,18- recipe: (draftState: S) => void18+ recipe: (draftState: S) => S | void19 ): S20 // curried invocations with inital state21 declare export default function produce<S, A, B, C>(22- recipe: (draftState: S, a: A, b: B, c: C) => void,22+ recipe: (draftState: S, a: A, b: B, c: C) => S | void,23 initialState: S24 ): (currentState: S | void, a: A, b: B, c: C) => S25 declare export default function produce<S, A, B>(26- recipe: (draftState: S, a: A, b: B) => void,26+ recipe: (draftState: S, a: A, b: B) => S | void,27 initialState: S28 ): (currentState: S | void, a: A, b: B) => S29 declare export default function produce<S, A>(30- recipe: (draftState: S, a: A) => void,30+ recipe: (draftState: S, a: A) => S | void,31 initialState: S32 ): (currentState: S | void, a: A) => S33 declare export default function produce<S>(34- recipe: (draftState: S) => void,34+ recipe: (draftState: S) => S | void,35 initialState: S36 ): (currentState: S | void) => S37 declare export default function produce<S>(38- recipe: (draftState: S, ...extraArgs: any[]) => void,38+ recipe: (draftState: S, ...extraArgs: any[]) => S | void,39 initialState: S40 ): (currentState: S | void, ...extraArgs: any[]) => S41 // curried invocations without inital state42 declare export default function produce<S, A, B, C>(43- recipe: (draftState: S, a: A, b: B, c: C) => void43+ recipe: (draftState: S, a: A, b: B, c: C) => S | void44 ): (currentState: S, a: A, b: B, c: C) => S45 declare export default function produce<S, A, B>(46- recipe: (draftState: S, a: A, b: B) => void46+ recipe: (draftState: S, a: A, b: B) => S | void47 ): (currentState: S, a: A, b: B) => S48 declare export default function produce<S, A>(49- recipe: (draftState: S, a: A) => void49+ recipe: (draftState: S, a: A) => S | void50 ): (currentState: S, a: A) => S51 declare export default function produce<S>(52- recipe: (draftState: S) => void52+ recipe: (draftState: S) => S | void53 ): (currentState: S) => S54 declare export default function produce<S>(55- recipe: (draftState: S, ...extraArgs: any[]) => void55+ recipe: (draftState: S, ...extraArgs: any[]) => S | void56 ): (currentState: S, ...extraArgs: any[]) => S57 /**58 * Automatically freezes any state trees generated by immer.59 * This protects against accidental modifications of the state tree outside of an immer function.10 unmodified lines