Skip to content
Myr

immutable.ts

This file

Path

__tests__/immutable.ts

66 lines · 1.6 KiB · TypeScript

Last changed by

feat(ts): Support typescript 3.4Alec Larsonbefore adoption2868065

History of this file

Take it

fix(ts): ensure produce returns an immutable typealeclarsonbefore adoptiondd25143

lines 1–16why, one step back
1import {Immutable} from "../dist/immer.js"
23// prettier-ignore4type Exact<A, B> = (<T>() => T extends A ? 1 : 0) extends (<T>() => T extends B ? 1 : 0)5 ? (A extends B ? (B extends A ? unknown : never) : never)6 : never78/** Fails when `actual` and `expected` have different types. */9declare const exactType: <Actual, Expected>(10 actual: Actual & Exact<Actual, Expected>,11 expected: Expected & Exact<Actual, Expected>12) => Expected1314// array in tuple15{16 let val = {} as Immutable<[string[], 1]>

feat(ts): Support typescript 3.4Alec Larsonbefore adoption2868065

line 17why, one step back
17 exactType(val, {} as readonly [ReadonlyArray<string>, 1])

fix(ts): ensure produce returns an immutable typealeclarsonbefore adoptiondd25143

lines 18–22why, one step back
18}
1920// tuple in array21{22 let val = {} as Immutable<[string, 1][]>

feat(ts): Support typescript 3.4Alec Larsonbefore adoption2868065

line 23why, one step back
23 exactType(val, {} as ReadonlyArray<readonly [string, 1]>)

fix(ts): ensure produce returns an immutable typealeclarsonbefore adoptiondd25143

lines 24–28why, one step back
24}
2526// tuple in tuple27{28 let val = {} as Immutable<[[string, 1], 1]>

feat(ts): Support typescript 3.4Alec Larsonbefore adoption2868065

line 29why, one step back
29 exactType(val, {} as readonly [readonly [string, 1], 1])

fix(ts): ensure produce returns an immutable typealeclarsonbefore adoptiondd25143

lines 30–40why, one step back
30}
3132// array in array33{34 let val = {} as Immutable<string[][]>35 exactType(val, {} as ReadonlyArray<ReadonlyArray<string>>)36}3738// tuple in object39{40 let val = {} as Immutable<{a: [string, 1]}>

feat(ts): Support typescript 3.4Alec Larsonbefore adoption2868065

line 41why, one step back
41 exactType(val, {} as {readonly a: readonly [string, 1]})

fix(ts): ensure produce returns an immutable typealeclarsonbefore adoptiondd25143

lines 42–46why, one step back
42}
4344// object in tuple45{46 let val = {} as Immutable<[{a: string}, 1]>

feat(ts): Support typescript 3.4Alec Larsonbefore adoption2868065

line 47why, one step back
47 exactType(val, {} as readonly [{readonly a: string}, 1])

fix(ts): ensure produce returns an immutable typealeclarsonbefore adoptiondd25143

lines 48–66why, one step back
48}
4950// array in object51{52 let val = {} as Immutable<{a: string[]}>53 exactType(val, {} as {readonly a: ReadonlyArray<string>})54}5556// object in array57{58 let val = {} as Immutable<Array<{a: string}>>59 exactType(val, {} as ReadonlyArray<{readonly a: string}>)60}6162// object in object63{64 let val = {} as Immutable<{a: {b: string}}>65 exactType(val, {} as {readonly a: {readonly b: string}})66}