Skip to content

Releases: everweij/typescript-result

3.5.3-beta.1

09 Sep 20:05
Compare
Choose a tag to compare
3.5.3-beta.1 Pre-release
Pre-release
v3.5.3-beta.1

fixes type issue where `Result.Error<E>` and `Result.Ok<V>` is not in…

3.5.2

10 Aug 18:02
dce9eed
Compare
Choose a tag to compare

Fixes

  • See #22 - Result.try and Result.fromAsyncCatching now catch exceptions that are thrown inside the transform-error callbacks.

Thanks @PeterD1524 !

3.5.1

21 Jul 08:18
Compare
Choose a tag to compare

Fixes

  • See #19 - Fixes issue where TS had trouble inferring the Result value when the shape of a value has some structural overlap with a Result type (e.g. { value: string }.

3.5.0

20 Jul 08:33
Compare
Choose a tag to compare

Minor changes:

  • Adds match() to Result, introducing basic pattern matching to the lib. See docs for more info about this feature.

     declare const result: Result<number, ErrorA | ErrorB>;
     
     if (!result.ok) {
       result
         .match()
         .when(ErrorA, () => /* handle error a */)
         .when(ErrorB, () => /* handle error b */)
         .run()
     }
  • Adds ok property on Result as the main way to check whether a result is a success or failure. See updated docs. This makes error handling a bit simpler, and allows us to more easily use a result with a pattern-matching lib like ts-pattern. As a result, isOk() and isError() are marked for deprecation.

    declare const result: Result<number, ErrorA | ErrorB>;
    
    // before
    if (result.isError()) {
      result.error; // ErrorA | ErrorB
    } else {
      result.value; // number
    }
    
    // after
    if (!result.ok) {
      result.error; // ErrorA | ErrorB
    } else {
      result.value; // number
    }
  • Strings passed to Result.error are now constant:

    // before
    const result = Result.error("some-error"); // Result.Error<string>
    
    // after
    const result = Result.error("some-error"); // Result.Error<"some-error">;

3.5.0-beta.1

19 Jul 19:53
Compare
Choose a tag to compare
3.5.0-beta.1 Pre-release
Pre-release
v3.5.0-beta.1

adds `match` functionality, simpler narrowing using `ok` (deprecating…

3.4.1

19 Jul 16:43
Compare
Choose a tag to compare

Fixes:

  • See #18 - Due to an @internal annotation, the generator syntax (yield*, etc) wasn't working correctly. Removing the annotations on [Symbol.iterator]() solved the issue.

3.4.0

16 Jul 10:42
Compare
Choose a tag to compare

Minor Changes

  • See #16: we better narrow Result.Ok / Result.Error when using Result.isOk() and Result.isError().

Fixes

  • See #17: we now ignore any mapped values when a result can only be a failure, and likewise ignore the returned value when recovering from results that can only be successful.

3.4.0-beta.2

11 Jul 20:10
Compare
Choose a tag to compare
3.4.0-beta.2 Pre-release
Pre-release
v3.4.0-beta.2

separates result creation into own factory class

3.3.0

04 Jul 12:51
Compare
Choose a tag to compare

Minor changes

  • adds optional transformErrorFn callback to Result.wrap
  • adds initial support for generator functions to create and work with results

3.3.0-beta.2

03 Jul 10:52
Compare
Choose a tag to compare
3.3.0-beta.2 Pre-release
Pre-release
v3.3.0-beta.2

adds overload to Result.gen and Result.genCatching for passing the th…