Add Type To Caught Errors

JavaScript pattern

Add any type annotation to caught errors. It is a common source of tsc errors.

Basic example

BEFORE
function foo() {
  try {
    console.log('tada');
  } catch (e) {
    console.log('oops');
  }
}

try {
  console.log('tada');
} catch (e: Foo) {
  console.log('oops');
}
AFTER
function foo() {
  try {
    console.log('tada');
  } catch (e: any) {
    console.log('oops');
  }
}

try {
  console.log('tada');
} catch (e: Foo) {
  console.log('oops');
}