catched-error-message
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

catched-error-message

Why

Because you would like to run code as below:

try {
  throw new Error("some crazy stuff");
} catch (error) {
  doSomethingWithErrorMessage({ message: error.message });
}

But TypeScript defaults error type to unknown. And this is actually correct, since you can throw literally anything:

throw 'messgae'
throw 123
throw {but: 'why?'}
throw null
throw undefined
...

Solution

This little package is a solution for thi problem. Just use it as below:

try {
  throw new Error("some crazy stuff");
} catch (error) {
  doSomethingWithErrorMessage({ message: getErrorMessage(error) });
}

And voilà, you get your message, no TS error.

Package Sidebar

Install

npm i catched-error-message

Weekly Downloads

283

Version

0.0.1

License

MIT

Unpacked Size

7.07 kB

Total Files

10

Last publish

Collaborators

  • tommybernaciak