Skip to content
Myr

Improved typings as suggested by #109. Improved typings of initialState

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent 8e42349 · Browse files · 4 files+163 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+163 added−19 removed

  • tests:+90 added−0 removed
  • other:+73 added−19 removed

4 files+163 added−19 removed

modified:__tests__/flow/flow.js.flow+29 added
29 unmodified lines
30produce({x: 3})3132// $ExpectError33produce({x: 3}, [])3435{36 // curried & initial arg37 const f = produce((state, increment: number) => {38 state.x += increment39 }, { x: 3})4041 // $ExpectError Too few arguments42 f({x : 5})4344 // $ExpectError45 f({x : 5}, "test")4647 f({x : 5}, 3)4849 f(undefined, 3)50}5152{53 // curried f & no initial arg54 const f2 = produce((state: {x:number}, increment: number) => {55 state.x += increment56 })5758 f2({x : 5}, 3)5960 // $ExpectError61 f2(undefined, 3)62}
added:__tests__/flow/ts.ts+61 added
modified:src/immer.d.ts+45 added-10 removed
modified:src/immer.js.flow+28 added-9 removed
15 unmodified lines
16declare export default function produce<S>(17 currentState: S,18 recipe: (draftState: S) => void19): S20// curried invocations20// curried invocations with inital state21declare export default function produce<S, A, B, C>(22 recipe: (draftState: S, a: A, b: B, c: C) => void,23 initialState?: S24): (currentState: S, a: A, b: B, c: C) => S23 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,27 initialState?: S28): (currentState: S, a: A, b: B) => S27 initialState: S28): (currentState: S | void, a: A, b: B) => S29declare export default function produce<S, A>(30 recipe: (draftState: S, a: A) => void,31 initialState?: S32): (currentState: S) => S31 initialState: S32): (currentState: S | void, a: A) => S33declare export default function produce<S>(34 recipe: (draftState: S) => void,35 initialState: S36): (currentState: S | void) => S37declare export default function produce<S>(38 recipe: (draftState: S, ...extraArgs: any[]) => void,35 initialState?: S39 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) => 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) => void47): (currentState: S, a: A, b: B) => S48declare export default function produce<S, A>(49 recipe: (draftState: S, a: A) => void50): (currentState: S, a: A) => S51declare export default function produce<S>(52 recipe: (draftState: S) => void53): (currentState: S) => S54declare export default function produce<S>(55 recipe: (draftState: S, ...extraArgs: any[]) => void56): (currentState: S, ...extraArgs: any[]) => S3757/**58 * Automatically freezes any state trees generated by immer.59 * This protects against accidental modifications of the state tree outside of an immer function.60 * This comes with a performance impact, so it is recommended to disable this option in production.
9 unmodified lines