// @flow import produce, {setAutoFreeze, setUseProxies, produce as produce2, applyPatches, Patch, original} from "../../src/immer" setAutoFreeze(true) setUseProxies(true) // we really don't want this code to actually execute.. const result = produce({x: 3}, draft => { draft.x = 4 // $ExpectError console.log(draft.y) }) console.log(result.x) const result2 = produce({x: 3}, draft => { return {x: 4} }) console.log(result2.x) const f = produce((draft): {x: number} => { return {x: 4} }) f({x: 3}) const f2 = produce((draft): void => {}) f2({x: 3}) // $ExpectError setAutoFreeze(3) // $ExpectError console.log(result.y) // $ExpectError produce() // $ExpectError produce({x: 3}) // $ExpectError produce({x: 3}, []) { // curried & initial arg const f = produce( (state, increment: number): void => { state.x += increment }, {x: 3} ) // $ExpectError Too few arguments f({x: 5}) // $ExpectError f({x: 5}, "test") f({x: 5}, 3) f(undefined, 3) } { // curried f & no initial arg const f2 = produce((state: {x: number}, increment: number): void => { state.x += increment }) f2({x: 5}, 3) // $ExpectError f2(undefined, 3) } { // $ExpectError produce2({x: 3}) const result = produce2({x: 3}, draft => { draft.x = 4 // $ExpectError console.log(draft.y) }) } { let p: Patch[] = [] produce({ }, d=> {}, (patches, inverse) => { p = patches }) applyPatches({}, p) } { produce({x: 3}, draftState => { let a = original(draftState) if (a) { a.x // $ExpectError a.y } }) } { produce([1], draftState => { const a = original(draftState); if (a) { const b: number = a[0]; // $ExpectError const c: string = a[0]; } }) }