Reputation: 923
My function:
buildErrorMessage(
{
originalError,
// ...
}: {
originalError?: Error;
// ...
}): string
{
/* ... */
}
When I try to use this function in catch block, the rule no-unsafe-assignment of typescript-eslint tells me that I trying to assign the value of any
type:
try {
// ...
} catch (error) {
throw new Error(buildErrorMessage({
originalError: error,
// ...
}));
}
Well, which data error
could contain besides Error
?
Upvotes: 2
Views: 1581
Reputation: 664599
Typescript is right here: any
value can be throw
n and will get caught in your catch
clause. Sure, it's best practice to throw Error
instances, but Typescript won't assume that you do that.
Upvotes: 3