Type-Safe Errors for JS & TypeScript
Addresses https://github.com/supermacro/neverthrow/issues/488 & implements the .fromThrowable
method on ResultAsync
.
Thanks to @ehaynes99 for implementing this :rocket:
:point_right: Reminder; I'm looking for a maintainer to help out:
neverthrow
now can support implicit return whenever there is an Err
instance inside of a generator.
Context: https://github.com/supermacro/neverthrow/pull/448
Thank you to @tsuburin for the contribution :rocket:
Additionally, the previous functionality around increasing the tuple size supported by neverthrow
is now live and out of beta. Context: https://github.com/supermacro/neverthrow/releases/tag/v6.0.1-0
I am a simple man - I like my tuples like my coffee; small (but strong). But some of you are out here trying to wreak havoc on the world with very large tuples. Now you get type inference on these too 🙂
This is a fix for https://github.com/supermacro/neverthrow/issues/441
The fix allows for type inference on very large tuples (limit of 49).
Given the sensitive nature of the changes made at the type level, I've opted to release this incrementally and as an opt-in functionality for now.
To get this change, you'll need to update your neverthrow
installation to use the @beta
tag.
> npm install neverthrow@beta
I'll wait a bit before moving this over to default
on npm.
The combine*
family of functions (both sync and async) broke any codebase that called these functions on arrays of varying lengths when the previous release was shipped:
https://github.com/supermacro/neverthrow/releases/tag/v5.1.0
The following fix was implemented to address this issue and ensure that arrays (not just tuples) work with the combine*
family of functions.
https://github.com/supermacro/neverthrow/pull/435
Because we are now explicitly depending on TypeScript's variadic tuple types feature, which came out in v4 of TypeScript:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#variadic-tuple-types
Thank you to @ghost91- for implementing the fix 🙏
Thanks to @incetarik for fixing a long-lasting developer inconvenience! https://github.com/supermacro/neverthrow/issues/226
Now, all of the "combine" functions can now infer types correctly and treat the list argument as a tuple rather than an unbounded list!
i.e. Rather than having to do:
Result.combine([ ok(123), err('whopps!') ] as const)
You can just omit the as const
now:
Result.combine([ ok(123), err('whopps!') ])
And neverthrow
can figure out the type of the above tuple on its own!
Thank you to @ccjmne @lmcsu and @msheakoski for this improvement :pray:
This release ships https://github.com/supermacro/neverthrow/pull/425 - which ensures that the E
type for ResultAsync.fromSafePromise
is never
by default - which makes a lot more sense / is more a "accurate" depiction of runtime behaviour.
Thank you to @tam-carre for implementing this fix!
Unfortunately there is no way to distinguish at runtime if an empty list is a list of ResultAsync
s or a list of Result
s.
Hence https://github.com/supermacro/neverthrow/issues/381 ... which could cause runtime exceptions!
So we've had to make the unfortunate decision of splitting combine
and combineWithAllErrors
into a synchronous version (behind the Result
namespace) and an asynchronous version (behind the ResultAsync
namespace).
So now we have:
Result.combine
Result.combineWithAllErrors
ResultAsync.combine
ResultAsync.combineWithAllErrors
... of course, this is a breaking change, and as such neverthrow
has now been bumped to version 5.0.0
Thanks to @bhvngt for this submission.
ResultAsync.fromPromise
and ResultAsync.fromSafePromise
are now able to accept anything that implements the PromiseLike
interface - in other words; anything that is "thenable". This includes objects such as Bluebird Promises and any other non-native promise-like object!
User kieran-osgood submitted a fix for a long standing issue whereby proxies were suddenly disappearing within calls to combine
:
https://github.com/supermacro/neverthrow/issues/228
This issue is now resolved!
Additionally, the docs have been updated to reference eslint-plugin-neverthrow
.