Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than b9f0029 point at it.

test(ts): use spec.tsAlec Larsonbefore adoptionb5abaed

line 1why, one step back
1import {assert, _} from "spec.ts"

Merge pull request #536 from immerjs/multi-bundleMichel Weststratebefore adoption0d87fc8

lines 2–4why, one step back
2import produce, {Immutable, castImmutable, enableAllPlugins} from "../src/immer"
34enableAllPlugins()

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 5why, one step back
5

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 6–11why, one step back
6test("types are ok", () => {
7 // array in tuple8 {9 let val = _ as Immutable<[string[], 1]>10 assert(val, _ as readonly [ReadonlyArray<string>, 1])11 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 12why, one step back
12

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 13–17why, one step back
13 // tuple in array
14 {15 let val = _ as Immutable<[string, 1][]>16 assert(val, _ as ReadonlyArray<readonly [string, 1]>)17 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 18why, one step back
18

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 19–23why, one step back
19 // tuple in tuple
20 {21 let val = _ as Immutable<[[string, 1], 1]>22 assert(val, _ as readonly [readonly [string, 1], 1])23 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 24why, one step back
24

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 25–29why, one step back
25 // array in array
26 {27 let val = _ as Immutable<string[][]>28 assert(val, _ as ReadonlyArray<ReadonlyArray<string>>)29 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 30why, one step back
30

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 31–35why, one step back
31 // tuple in object
32 {33 let val = _ as Immutable<{a: [string, 1]}>34 assert(val, _ as {readonly a: readonly [string, 1]})35 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 36why, one step back
36

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 37–41why, one step back
37 // object in tuple
38 {39 let val = _ as Immutable<[{a: string}, 1]>40 assert(val, _ as readonly [{readonly a: string}, 1])41 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 42why, one step back
42

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 43–47why, one step back
43 // array in object
44 {45 let val = _ as Immutable<{a: string[]}>46 assert(val, _ as {readonly a: ReadonlyArray<string>})47 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 48why, one step back
48

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 49–53why, one step back
49 // object in array
50 {51 let val = _ as Immutable<Array<{a: string}>>52 assert(val, _ as ReadonlyArray<{readonly a: string}>)53 }

chore: replace rollup with bili (#306)EGOISTbefore adoptionb9f0029

line 54why, one step back
54

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

lines 55–60why, one step back
55 // object in object
56 {57 let val = _ as Immutable<{a: {b: string}}>58 assert(val, _ as {readonly a: {readonly b: string}})59 }60

feat: general typing improvements for TS 3.7 and upMichel Weststratebefore adoptionf930ce1

lines 61–96why, one step back
61 // Map
62 {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 }96

feat: convert Immer to TypeScriptMichel Weststratebefore adoption52c9914

line 97why, one step back
97 expect(true).toBe(true)

feat: general typing improvements for TS 3.7 and upMichel Weststratebefore adoptionf930ce1

lines 98–118why, one step back
98})
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 back
119})