immutable.ts
This file
Path
__tests__/immutable.ts
119 lines · 2.4 KiB · TypeScript
Last changed by
Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
History of this fileTake it
The walk stopped after 200 commits: lines older than ff210d8 point at it.
test(ts): use spec.tsAlec Larsonbefore adoptionb5abaed
line 1why, one step back1import {assert, _} from "spec.ts"Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8
lines 2–4why, one step back2import produce, {Immutable, castImmutable, enableAllPlugins} from "../src/immer"34enableAllPlugins()Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 5why, one step back5feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 6–11why, one step back6test("types are ok", () => {7 // array in tuple8 {9 let val = _ as Immutable<[string[], 1]>10 assert(val, _ as readonly [ReadonlyArray<string>, 1])11 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 12why, one step back12feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 13–17why, one step back13 // tuple in array14 {15 let val = _ as Immutable<[string, 1][]>16 assert(val, _ as ReadonlyArray<readonly [string, 1]>)17 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 18why, one step back18feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 19–23why, one step back19 // tuple in tuple20 {21 let val = _ as Immutable<[[string, 1], 1]>22 assert(val, _ as readonly [readonly [string, 1], 1])23 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 24why, one step back24feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 25–29why, one step back25 // array in array26 {27 let val = _ as Immutable<string[][]>28 assert(val, _ as ReadonlyArray<ReadonlyArray<string>>)29 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 30why, one step back30feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 31–35why, one step back31 // tuple in object32 {33 let val = _ as Immutable<{a: [string, 1]}>34 assert(val, _ as {readonly a: readonly [string, 1]})35 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 36why, one step back36feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 37–41why, one step back37 // object in tuple38 {39 let val = _ as Immutable<[{a: string}, 1]>40 assert(val, _ as readonly [{readonly a: string}, 1])41 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 42why, one step back42feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 43–47why, one step back43 // array in object44 {45 let val = _ as Immutable<{a: string[]}>46 assert(val, _ as {readonly a: ReadonlyArray<string>})47 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 48why, one step back48feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 49–53why, one step back49 // object in array50 {51 let val = _ as Immutable<Array<{a: string}>>52 assert(val, _ as ReadonlyArray<{readonly a: string}>)53 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 54why, one step back54feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
lines 55–60why, one step back55 // object in object56 {57 let val = _ as Immutable<{a: {b: string}}>58 assert(val, _ as {readonly a: {readonly b: string}})59 }60feat: general typing improvements for TS 3.7 and upMichel Weststratebefore adoptionf930ce1
lines 61–96why, one step back61 // Map62 {63 let val = _ as Immutable<Map<string, string>>64 assert(val, _ as ReadonlyMap<string, string>)65 }6667 // Already immutable Map68 {69 let val = _ as Immutable<ReadonlyMap<string, string>>70 assert(val, _ as ReadonlyMap<string, string>)71 }7273 // object in Map74 {75 let val = _ as Immutable<Map<{a: string}, {b: string}>>76 assert(val, _ as ReadonlyMap<{readonly a: string}, {readonly b: string}>)77 }7879 // Set80 {81 let val = _ as Immutable<Set<string>>82 assert(val, _ as ReadonlySet<string>)83 }8485 // Already immutable Set86 {87 let val = _ as Immutable<ReadonlySet<string>>88 assert(val, _ as ReadonlySet<string>)89 }9091 // object in Set92 {93 let val = _ as Immutable<Set<{a: string}>>94 assert(val, _ as ReadonlySet<{readonly a: string}>)95 }96feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 97why, one step back97 expect(true).toBe(true)feat: general typing improvements for TS 3.7 and upMichel Weststratebefore adoptionf930ce1
lines 98–118why, one step back98})99100test("#381 produce immutable state", () => {101 const someState = {102 todos: [103 {104 done: false105 }106 ]107 }108109 const immutable = castImmutable(produce(someState, _draft => {}))110 assert(111 immutable,112 _ as {readonly todos: ReadonlyArray<{readonly done: boolean}>}113 )114})115116test("castImmutable preserves a value", () => {117 const x = {}118 expect(castImmutable(x)).toBe(x)feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914
line 119why, one step back119})