flow.js.flow
This file
Path
__tests__/flow/flow.js.flow
76 lines · 1.2 KiB
Last changed by
Merge branch 'kachkaev-add-failing-tests-for-recursive-use'Michel Weststratebefore adoption3db727b
History of this fileTake it
1// @flow2import produce, {setAutoFreeze, setUseProxies} from "../../src/immer"34setAutoFreeze(true)5setUseProxies(true)67// we really don't want this code to actually execute..8const result = produce({x: 3}, draft => {9 draft.x = 41011 // $ExpectError12 console.log(draft.y)13})1415console.log(result.x)1617const result2 = produce({x: 3}, draft => {18 return {x: 4}19})2021console.log(result2.x)2223const f = produce((draft): {x: number} => {24 return {x: 4}25})26f({x: 3})2728const f2 = produce((draft): void => {})29f2({x: 3})3031// $ExpectError32setAutoFreeze(3)3334// $ExpectError35console.log(result.y)3637// $ExpectError38produce()3940// $ExpectError41produce({x: 3})4243// $ExpectError44produce({x: 3}, [])4546{47 // curried & initial arg48 const f = produce(49 (state, increment: number): void => {50 state.x += increment51 },52 {x: 3}53 )5455 // $ExpectError Too few arguments56 f({x: 5})5758 // $ExpectError59 f({x: 5}, "test")6061 f({x: 5}, 3)6263 f(undefined, 3)64}6566{67 // curried f & no initial arg68 const f2 = produce((state: {x: number}, increment: number): void => {69 state.x += increment70 })7172 f2({x: 5}, 3)7374 // $ExpectError75 f2(undefined, 3)76}