Add Type To Caught Errors

JavaScript pattern

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


Apply with the Grit CLI
grit apply add_type_caught_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');
}