mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 01:13:56 +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;
|
|
}
|
|
}
|
|
}
|