Solve - Object is of type 'unknown' Error in TypeScript | bobbyhadz

PHOTO EMBED

Fri Sep 02 2022 10:08:05 GMT+0000 (UTC)

Saved by @Floony #typescript

async function fetchData() {
  try {
    await Promise.resolve(42);
  } catch (err) {
    if (err instanceof Error) {
      // โœ… TypeScript knows err is Error
      console.log(err.message);
    } else {
      console.log('Unexpected error', err);
    }
  }
}
content_copyCOPY

https://bobbyhadz.com/blog/typescript-object-is-of-type-unknown