Skip to content
Myr

flow.js.flow

This file

Path

__tests__/flow/flow.js.flow

133 lines · 2.0 KiB

Last changed by

fix(test): faulty .flowconfigaleclarsonbefore adoptione8fe4ba

History of this file

Take it

1// @flow2import produce, {3    setAutoFreeze,4    setUseProxies,5    produce as produce2,6    applyPatches,7    Patch,8    original9} from "../../dist/immer.js"1011setAutoFreeze(true)12setUseProxies(true)1314// we really don't want this code to actually execute..15const result = produce({x: 3}, draft => {16    draft.x = 41718    // $ExpectError19    console.log(draft.y)20})2122console.log(result.x)2324const result2 = produce({x: 3}, draft => {25    return {x: 4}26})2728console.log(result2.x)2930const f = produce(31    (draft): {x: number} => {32        return {x: 4}33    }34)35f({x: 3})3637const f2 = produce((draft): void => {})38f2({x: 3})3940// $ExpectError41setAutoFreeze(3)4243// $ExpectError44console.log(result.y)4546// $ExpectError47produce()4849// $ExpectError50produce({x: 3})5152// $ExpectError53produce({x: 3}, [])5455{56    // curried & initial arg57    const f = produce(58        (state, increment: number): void => {59            state.x += increment60        },61        {x: 3}62    )6364    // $ExpectError Too few arguments65    f({x: 5})6667    // $ExpectError68    f({x: 5}, "test")6970    f({x: 5}, 3)7172    f(undefined, 3)73}7475{76    // curried f & no initial arg77    const f2 = produce(78        (state: {x: number}, increment: number): void => {79            state.x += increment80        }81    )8283    f2({x: 5}, 3)8485    // $ExpectError86    f2(undefined, 3)87}8889{90    // $ExpectError91    produce2({x: 3})9293    const result = produce2({x: 3}, draft => {94        draft.x = 49596        // $ExpectError97        console.log(draft.y)98    })99}100101{102    let p: Patch[] = []103    produce(104        {},105        d => {},106        (patches, inverse) => {107            p = patches108        }109    )110    applyPatches({}, p)111}112113{114    produce({x: 3}, draftState => {115        let a = original(draftState)116        if (a) {117            a.x118            // $ExpectError119            a.y120        }121    })122}123124{125    produce([1], draftState => {126        const a = original(draftState)127        if (a) {128            const b: number = a[0]129            // $ExpectError130            const c: string = a[0]131        }132    })133}