DEV Community

loading...

Discussion on: Errors Are Not Exceptions

Collapse
lionelrowe profile image
lionel-rowe • Edited

In JavaScript, Errors are just another type of object. So you can return new Error('message') instead of throwing it, and TypeScript will modify the return type accordingly.

On the flipside, you can throw something that's not an Error if you really want. throw 'just a string', throw [error1, error2], etc. Though some linter configurations might complain at you if you do this.