The Situation
I am using TypeScript, and have a try / catch block. The caught error is typed (Error). I would like to use the error's message attribute.
I am using eslint with the @typescript-eslint/no-unsafe-assignment rule enabled.
The Code
try {
throw new Error('foo');
} catch (err: Error) {
const { message }: { message: string } = err;
return {
message: `Things exploded (${message})`,
};
}
The Problem
When I run my linter, I receive the following:
4:9 error Unsafe assignment of an any value @typescript-eslint/no-unsafe-assignment
This is confusing to me, since the error is typed (Error).
The Question
How can I catch an error in TypeScript and access the Error's properties?