Skip to content
Myr

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

2 files+24 added−15 removed

modified:__tests__/flow/flow.js.flow+13 added-4 removed
12 unmodified lines
13})1415console.log(result.x)1617const f2 = produce(draft => {})17const result2 = produce({x: 3}, draft => {18 return {x: 4};19})2021console.log(result2.x)2223const f = produce((draft): ({x: number}) => { return {x: 4}; });24f({x: 3});2526const f2 = produce((draft): void => {})27f2({x: 3})2829// $ExpectError30setAutoFreeze(3)
11 unmodified lines
42produce({x: 3}, [])4344{45 // curried & initial arg37 const f = produce((state, increment: number) => {46 const f = produce((state, increment: number): void => {47 state.x += increment48 }, { x: 3})4950 // $ExpectError Too few arguments
8 unmodified lines
59}6061{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 })6667 f2({x : 5}, 3)6869 // $ExpectError70 f2(undefined, 3)62}71}
modified:src/immer.js.flow+11 added-11 removed
13 unmodified lines
14 * @returns The next state: a new state, or the current state if nothing was modified15 */16declare export default function produce<S>(17 currentState: S,18 recipe: (draftState: S) => void18 recipe: (draftState: S) => S | void19): S20// curried invocations with inital state21declare 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) => S25declare 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) => S29declare 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) => S33declare export default function produce<S>(34 recipe: (draftState: S) => void,34 recipe: (draftState: S) => S | void,35 initialState: S36): (currentState: S | void) => S37declare 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 state42declare 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) => S45declare 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) => S48declare export default function produce<S, A>(49 recipe: (draftState: S, a: A) => void49 recipe: (draftState: S, a: A) => S | void50): (currentState: S, a: A) => S51declare export default function produce<S>(52 recipe: (draftState: S) => void52 recipe: (draftState: S) => S | void53): (currentState: S) => S54declare 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