I am getting the error while using async, await in useEffect hook.
useEffect(() => {
if (contentLoader) {
(async () => {
try {
const data = await promise;
setData(data);
} catch (errorObj) {
if (!errorObj?.value) { //here i'm getting --> errorObj: unknown Object is of type 'unknown'.
setError(errorObj);
console.log(`loading document error: ${errorObj}`);
}
}
})();
} else // something else
}, [..])
whats wrong in my code.
You're using TypeScript 4.4 or newer with [use-unknown-catch-variables] (https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#use-unknown-catch-variables) enabled.
The easiest fix, if you don't know the actual type of the error thrown, is to just tell TypeScript that it's any, not unknown.
catch (errorObj) {
->
catch (errorObj: any) {