-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathoverloads.spec.ts
More file actions
107 lines (99 loc) · 2.84 KB
/
overloads.spec.ts
File metadata and controls
107 lines (99 loc) · 2.84 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
import * as util from "../util";
test("overload function1", () => {
util.testFunction`
function abc(def: number): string;
function abc(def: string): string;
function abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
return abc(3);
`.expectToMatchJsResult();
});
test("overload function2", () => {
util.testFunction`
function abc(def: number): string;
function abc(def: string): string;
function abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
return abc("ghj");
`.expectToMatchJsResult();
});
test("overload method1", () => {
util.testFunction`
class myclass {
static abc(def: number): string;
static abc(def: string): string;
static abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
}
return myclass.abc(3);
`.expectToMatchJsResult();
});
test("overload method2", () => {
util.testFunction`
class myclass {
static abc(def: number): string;
static abc(def: string): string;
static abc(def: number | string): string {
if (typeof def == "number") {
return "jkl" + (def * 3);
} else {
return def;
}
}
}
return myclass.abc("ghj");
`.expectToMatchJsResult();
});
test("constructor1", () => {
util.testFunction`
class myclass {
num: number;
str: string;
constructor(def: number);
constructor(def: string);
constructor(def: number | string) {
if (typeof def == "number") {
this.num = def;
} else {
this.str = def;
}
}
}
const inst = new myclass(3);
return inst.num;
`.expectToMatchJsResult();
});
test("constructor2", () => {
util.testFunction`
class myclass {
num: number;
str: string;
constructor(def: number);
constructor(def: string);
constructor(def: number | string) {
if (typeof def == "number") {
this.num = def;
} else {
this.str = def;
}
}
}
const inst = new myclass("ghj");
return inst.str
`.expectToMatchJsResult();
});