/
deepCopy.ts
70 lines (50 loc) · 1.72 KB
/
deepCopy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { List, Map, Record, Set, Seq, DeepCopy, Collection } from 'immutable';
{
// Basic types
// $ExpectType { a: number; b: number; }
type Test = DeepCopy<{ a: number; b: number }>;
// ^?
// $ExpectType number
type TestA = Test['a'];
// ^?
}
{
// Iterables
// $ExpectType string[]
type Test = DeepCopy<string[]>;
// ^?
// $ExpectType number[]
type Keyed = DeepCopy<Collection.Indexed<number>>;
// ^?
}
{
// Immutable first-level types
// $ExpectType { [x: string]: string; }
type StringKey = DeepCopy<Map<string, string>>;
// $ExpectType { [x: string]: object; }
type ObjectKey = DeepCopy<Map<object, object>>;
// $ExpectType { [x: string]: object; [x: number]: object; }
type MixedKey = DeepCopy<Map<object | number, object>>;
// $ExpectType string[]
type ListDeepCopy = DeepCopy<List<string>>;
// $ExpectType string[]
type SetDeepCopy = DeepCopy<Set<string>>;
}
{
// Keyed
// $ExpectType { [x: string]: number; }
type Keyed = DeepCopy<Collection.Keyed<string, number>>;
// $ExpectType { [x: string]: number; [x: number]: number; }
type KeyedMixed = DeepCopy<Collection.Keyed<string | number, number>>;
// $ExpectType { [x: string]: number; [x: number]: number; }
type KeyedSeqMixed = DeepCopy<Seq.Keyed<string | number, number>>;
// $ExpectType { [x: string]: number; [x: number]: number; }
type MapMixed = DeepCopy<Map<string | number, number>>;
}
{
// Nested
// $ExpectType { map: { [x: string]: string; }; list: string[]; set: string[]; }
type NestedObject = DeepCopy<{ map: Map<string, string>; list: List<string>; set: Set<string>; }>;
// $ExpectType { map: { [x: string]: string; }; }
type NestedMap = DeepCopy<Map<'map', Map<string, string>>>;
}