While working with a React-Query mutation, I encountered an issue where my component displays an error message but TypeScript does not recognize the mutation.error property as type Error:
if (mutation.isError){
console.log(mutation.error.message); // Property 'message' does not exist on type 'unknown'.
console.log((mutation.error as Error).message); // works
}
Is there a way to explicitly inform TypeScript that mutation.error is of type Error object?