mirror of
https://github.com/swc-project/swc.git
synced 2024-12-27 15:42:51 +03:00
24 lines
587 B
TypeScript
24 lines
587 B
TypeScript
declare function isFooError(x: any): x is { type: 'foo'; dontPanic(); };
|
|
|
|
function tryCatch() {
|
|
try {
|
|
// do stuff...
|
|
}
|
|
catch (err) { // err is implicitly 'any' and cannot be annotated
|
|
|
|
if (isFooError(err)) {
|
|
err.dontPanic(); // OK
|
|
err.doPanic(); // ERROR: Property 'doPanic' does not exist on type '{...}'
|
|
}
|
|
|
|
else if (err instanceof Error) {
|
|
err.message;
|
|
err.massage; // ERROR: Property 'massage' does not exist on type 'Error'
|
|
}
|
|
|
|
else {
|
|
throw err;
|
|
}
|
|
}
|
|
}
|