mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 10:12:42 +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;
|
|
}
|
|
}
|
|
}
|