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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In JavaScript,
Error
s are just another type of object. So you canreturn 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 anError
if you really want.throw 'just a string'
,throw [error1, error2]
, etc. Though some linter configurations might complain at you if you do this.