I have the following code snippet:
try {
// api call
} catch (error) {
if (typeof error === 'object' && error !== null && 'message' in error) {
if (typeof error.message === 'string') {
if (error.message.match(userRejectedError)) {
// do something
} else {
// do something else
}
}
}
}
However, I am encountering the error:
Property 'message' does not exist on type 'object'
.
Why is this happening when I have made sure to check all necessary types?
Edit: TSConfig
{
"compilerOptions": {
"baseUrl": ".",
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
},
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": false,
"noImplicitAny": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}