-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathimplicitIndexSignatures.js
More file actions
120 lines (111 loc) · 2.99 KB
/
implicitIndexSignatures.js
File metadata and controls
120 lines (111 loc) · 2.99 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//// [implicitIndexSignatures.ts]
type StringMap = { [x: string]: string };
const empty1 = {};
let empty2: {};
const names1 = { a: "foo", b: "bar" };
let names2: { a: string, b: string };
let map: StringMap;
map = { x: "xxx", y: "yyy" };
map = empty1;
map = empty2;
map = names1;
map = names2;
declare function getStringIndexValue<T>(map: { [x: string]: T }): T;
declare function getNumberIndexValue<T>(map: { [x: number]: T }): T;
function f1() {
const o1 = { a: 1, b: 2 };
let o2: { a: number, b: number };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
}
function f2() {
const o1 = { a: "1", b: "2" };
let o2: { a: string, b: string };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
}
function f3() {
const o1 = { a: 1, b: "2" };
let o2: { a: number, b: string };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
}
function f4() {
const o1 = { 0: "0", 1: "1", count: 2 };
let o2: { 0: string, 1: string, count: number };
const v1 = getStringIndexValue(o1);
const v2 = getStringIndexValue(o2);
const v3 = getNumberIndexValue(o1);
const v4 = getNumberIndexValue(o2);
}
function f5() {
enum E1 { A, B }
enum E2 { A = "A", B = "B" }
enum E3 { A = 0, B = "B" }
const v1 = getStringIndexValue(E1);
const v2 = getStringIndexValue(E2);
const v3 = getStringIndexValue(E3);
const v4 = getNumberIndexValue(E1);
const v5 = getNumberIndexValue(E2);
const v6 = getNumberIndexValue(E3);
}
//// [implicitIndexSignatures.js]
var empty1 = {};
var empty2;
var names1 = { a: "foo", b: "bar" };
var names2;
var map;
map = { x: "xxx", y: "yyy" };
map = empty1;
map = empty2;
map = names1;
map = names2;
function f1() {
var o1 = { a: 1, b: 2 };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
}
function f2() {
var o1 = { a: "1", b: "2" };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
}
function f3() {
var o1 = { a: 1, b: "2" };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
}
function f4() {
var o1 = { 0: "0", 1: "1", count: 2 };
var o2;
var v1 = getStringIndexValue(o1);
var v2 = getStringIndexValue(o2);
var v3 = getNumberIndexValue(o1);
var v4 = getNumberIndexValue(o2);
}
function f5() {
var E1;
(function (E1) {
E1[E1["A"] = 0] = "A";
E1[E1["B"] = 1] = "B";
})(E1 || (E1 = {}));
var E2;
(function (E2) {
E2["A"] = "A";
E2["B"] = "B";
})(E2 || (E2 = {}));
var E3;
(function (E3) {
E3[E3["A"] = 0] = "A";
E3["B"] = "B";
})(E3 || (E3 = {}));
var v1 = getStringIndexValue(E1);
var v2 = getStringIndexValue(E2);
var v3 = getStringIndexValue(E3);
var v4 = getNumberIndexValue(E1);
var v5 = getNumberIndexValue(E2);
var v6 = getNumberIndexValue(E3);
}