forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatchClauseWithTypeAnnotation.js
102 lines (95 loc) · 2.62 KB
/
catchClauseWithTypeAnnotation.js
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
//// [catchClauseWithTypeAnnotation.ts]
type any1 = any;
type unknown1 = unknown;
function fn(x: boolean) {
// no type annotation allowed other than `any` and `unknown`
try { } catch (x) { } // should be OK
try { } catch (x: any) { } // should be OK
try { } catch (x: any1) { } // should be OK
try { } catch (x: unknown) { } // should be OK
try { } catch (x: unknown1) { } // should be OK
try { } catch (x) { x.foo; } // should be OK
try { } catch (x: any) { x.foo; } // should be OK
try { } catch (x: any1) { x.foo; } // should be OK
try { } catch (x: unknown) { console.log(x); } // should be OK
try { } catch (x: unknown1) { console.log(x); } // should be OK
try { } catch (x: unknown) { x.foo; } // error in the body
try { } catch (x: unknown1) { x.foo; } // error in the body
try { } catch (x: Error) { } // error in the type
try { } catch (x: object) { } // error in the type
try { console.log(); }
// @ts-ignore
catch (e: number) { // e should not be a `number`
console.log(e.toLowerCase());
}
// minor bug: shows that the `catch` argument is skipped when checking scope
try { } catch (x) { let x: string; }
try { } catch (x) { var x: string; }
try { } catch (x) { var x: boolean; }
}
//// [catchClauseWithTypeAnnotation.js]
function fn(x) {
// no type annotation allowed other than `any` and `unknown`
try { }
catch (x) { } // should be OK
try { }
catch (x) { } // should be OK
try { }
catch (x) { } // should be OK
try { }
catch (x) { } // should be OK
try { }
catch (x) { } // should be OK
try { }
catch (x) {
x.foo;
} // should be OK
try { }
catch (x) {
x.foo;
} // should be OK
try { }
catch (x) {
x.foo;
} // should be OK
try { }
catch (x) {
console.log(x);
} // should be OK
try { }
catch (x) {
console.log(x);
} // should be OK
try { }
catch (x) {
x.foo;
} // error in the body
try { }
catch (x) {
x.foo;
} // error in the body
try { }
catch (x) { } // error in the type
try { }
catch (x) { } // error in the type
try {
console.log();
}
// @ts-ignore
catch (e) { // e should not be a `number`
console.log(e.toLowerCase());
}
// minor bug: shows that the `catch` argument is skipped when checking scope
try { }
catch (x) {
var x_1;
}
try { }
catch (x) {
var x;
}
try { }
catch (x) {
var x;
}
}