Skip to content

Releases: supermacro/neverthrow

Inline function docs

20 Mar 14:48
Compare
Choose a tag to compare

This release adds in-line docs for the Result variants. Now, when using a LSP-supported editor, you'll have docs as you hover a Result method.

Thanks to @Liam-Tait for the contribution!

✨ New `combineWithAllErrors` utility function ✨

16 Mar 01:32
Compare
Choose a tag to compare

neverthrow now exposes a combineWithAllErrors function that is the "lazy" (for lack of a better word) equivalent of combine.

This means that rather than short-circuiting upon finding the first Err value, combineWithAllErrors will continue consuming the Result / ResultAsync list until the end and return a list containing all the Err values that it found.

Thanks to @tobloef for the contribution 🚀

Bugfix: Do not unwrap / destructure array contents into combine list.

25 Feb 15:44
Compare
Choose a tag to compare

This release patches a bug where calling combine on a Result<T, E>[] or ResultAsync<T, E>[] and the T values were lists, then those lists would get concatenated into a single output list:

Example:

import { combine, ok } from 'neverthrow'

combine([
  ok([ 1, 2, 3 ]),
  ok([ 'hello', 'world ])
])

// before v4.1.1, the above would incorrectly return [ 1, 2, 3, 'hello', 'world' ]
// 
// actual output should be [ [ 1,2,3 ], [ 'hello', 'world' ] ] 

The fix of the bug can be found here:

a5e66a8

I decided to continue using Array.prototype.concat in spite of this subtlety because it does not mutate references (unlike Array.prototype.push).

All `andThen` variations now allow you to return distinct error types! 🔥 (now out of beta)

15 Feb 16:53
Compare
Choose a tag to compare

This release:

All `andThen` variations now allow you to return distinct error types! 🔥

26 Jan 17:22
Compare
Choose a tag to compare

I finally caved and have gone ahead and "loosened" the restriction that all andThen variations (Result.andThen, Result.asyncAndThen, and ResultAsync.andThen) had before. The restriction prevented the callback inside all andThen variations from returning a distinct / different error type.

See #30 for more context on the "problem" that this addresses.

This release is downloadable behind a beta tag on npm.

> npm install neverthrow@beta

Docs have been updated to reflect this change.

Here's an example diff.

-   andThen<U>(f: (t: T) => Result<U, E>): Result<U, E> {
+   andThen<U, F>(f: (t: T) => Result<U, F>): Result<U, E | F> {

And here is the full diff:

8f87ef0

Fix invalid overload type for combine

17 Jan 19:34
Compare
Choose a tag to compare

The combine overload for ResultAsync lists was incorrect. Previously the overload stated that the return type of a combine invocation with a list of ResultAsyncs was a Result.

This patch fixes this error and now combine's type on ResultAsyncs correctly specifies that the return value will be a ResultAsync.

✨ New `fromSafePromise` method on ResultAsync✨

15 Jan 16:44
Compare
Choose a tag to compare

Breaking Change: This release changes the API of the original ResultAsync.fromPromise method to require a error handler callback.

In addition, there is now a new static class method called ResultAsync.fromSafePromise that does not take a error handler callback under the assumption that you are calling this method with a promise that does not ever throw.

✨ `combine` now works on heterogeneous lists ✨ + new `orElse` method! ✨

13 Jan 19:16
Compare
Choose a tag to compare

Combine v2

The combine utility function now lets you combine lists containing different kinds of results! The recommended way that you use combine when calling it with a heterogeneous list is to either declare a tuple type that describes each element in the list, or declare the list as const.

New orElse method

The orElse method (implemented on both Result and ResultAsync) allows for error-recovery where you want to potentially convert an E into T.

Improved error messages during tests & optional stack trace generation

28 Dec 15:44
Compare
Choose a tag to compare

This release swaps out the usage of a native Error with a custom JS Object for the _unsafeUnwrap and _unsafeUnwrapErr methods. This means that stack traces will not be generated by default.

The aforementioned methods will not generate a stack trace because Jest's error messages become less helpful.

If for some reason you want to log stack traces (because you're using these methods in a non-test environment ... which would be considered .... unsafe) for thrown exceptions, you can call the above methods with the following config object as an argument:

_unsafeUnwrapErr({
  withStackTrace: true,
})

Make Result instances comparable

22 Dec 15:48
Compare
Choose a tag to compare

#214 changes the match method from being implemented as a instance property to being implemented as a method on the prototype chain.

Therefore all instances of Result share the same reference in their match method. This allows testing libraries like Jest to make appropriate object comparisons / diffs.

Thanks to @bluenote10 for the submission!