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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
//// [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; }
try { } catch ({ x }) { } // 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); } // error in the destructure
try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
try { } catch ({ x }: object) { } // error in the type
try { } catch ({ x }: Error) { } // error in the type
}
//// [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;
}
try { }
catch (_a) {
var x_2 = _a.x;
} // should be OK
try { }
catch (_b) {
var x_3 = _b.x;
x_3.foo;
} // should be OK
try { }
catch (_c) {
var x_4 = _c.x;
x_4.foo;
} // should be OK
try { }
catch (_d) {
var x_5 = _d.x;
console.log(x_5);
} // error in the destructure
try { }
catch (_e) {
var x_6 = _e.x;
console.log(x_6);
} // error in the destructure
try { }
catch (_f) {
var x_7 = _f.x;
} // error in the type
try { }
catch (_g) {
var x_8 = _g.x;
} // error in the type
}
|