A "universal library" should respect language best practices. There is a standard way to deal with errors in javascript and you just introduce a new solution that is really questionable in my opinion.
You say throwing an error would force the use of a try catch block but your solution introduce the need to check the result too.
One big problem is that Error is a truthy value so that is error prone for the caller of the function :
if(isEmptyArray({})){// oups its not an empty array}
It is a bad practice to have a function that can return different types in js (boolean | Error) and having the caller to check the return type. If you really need to, you could use a tuple or an object that the caller can deconstruct.
Some comments have been hidden by the post's author - find out more
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.
A "universal library" should respect language best practices. There is a standard way to deal with errors in javascript and you just introduce a new solution that is really questionable in my opinion.
You say throwing an error would force the use of a try catch block but your solution introduce the need to check the result too.
One big problem is that
Error
is a truthy value so that is error prone for the caller of the function :It is a bad practice to have a function that can return different types in js (boolean | Error) and having the caller to check the return type. If you really need to, you could use a tuple or an object that the caller can deconstruct.