Closed bwbuchanan closed 6 years ago
Thanks for the suggestion! The reason it's currently implemented the way it is is that I'm concerned with someone porting a legacy codebase to prelude. If that codebase had a practice of throwing things which are not Error, then porting could become harder. On the other hand I suppose one could cast to any to make it work for that legacy's case, like
getOrThrow(<any>"oops")
not sure what's right in this case. I'll think it through a little more.
Oh but getOrThrow takes and throws strings! Sorry I checked too fast. You're right this is wrong it should throw errors by default. Maybe it should take Error|string and if given a string, wrap the string in Error for convenience.
Sounds good. I agree.
On Thu, Aug 30, 2018 at 23:07 emmanueltouzery notifications@github.com wrote:
Oh but getOrThrow takes and throws strings! Sorry I checked too fast. You're right this is wrong it should throw errors by default. Maybe it should take Error|string and if given a string, wrap the string in Error for convenience.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/emmanueltouzery/prelude.ts/issues/15#issuecomment-417467607, or mute the thread https://github.com/notifications/unsubscribe-auth/AABHmlvWpFIKsSKCxByipKRpCPLBTnWjks5uWFQtgaJpZM4WTnNx .
I pushed the change to master, this will go in 0.8.0. There are still other things I want to change before releasing 0.8.0 though, so I'm not releasing this yet. Thanks for the suggestion again!
Option.getOrThrow() currently takes a string as its argument. I think that it should take an Error instance, because throwing bare strings is generally considered poor Javascript coding practice.
Current method:
Suggested: