Releases: everweij/typescript-result
Releases · everweij/typescript-result
3.1.1
3.1.0
Minor changes
- adds
toTuple()
to both theResult
andAsyncResult
class, allowing you to destructure a result and use TypeScript's narrowing capabilities (instead of having to check withisOk()
andisError()
).
declare const result: Result<number, ErrorA>;
const [value, error] = result.toTuple();
if (error) {
// error is ErrorA
} else {
// at this point the value must be a number
}
// or 'Go-style'
if (error === null) {
// do something with the value
}
3.0.0
2.1.1
2.1.0
Minor changes
- added
mapError
method to both theResult
andAsyncResult
instances, which allows you to transform the encapsulated error of a failed result (#9 ) - added an additional parameter to the
mapCatching
method (transformErrorFn
) which allows you to transform the potential error caught while transforming. (#9)
Thanks @derkbell for suggesting this improvement and helping out with a solution!
Fixes
- Moves the default export condition to last position in
package.json
. See #6.
Thanks @trombipeti for helping and pointing this out!
2.0.0
2.0.0-beta.1
v2.0.0-beta.1 adds release workflow
v1.2.0
- Result.safe() now accepts a error-class as parameter:
class CustomError() {}
const result = Result.safe(CustomError, () => 2 * 2);
- Result.safe() now accepts a callback which returns another Result an will merge both Results:
class CustomError() {}
function doStuff(): Result<CustomError, number> {}
const result = Result.safe(() => doStuff()); // Result<Error | CustomError, number>
- Result#map() now accepts a callback that returns another result (flat-map) or a callback that transforms the value directly:
function doStuff(): Result<CustomError, number> {}
const result = doStuff().map(num => num * 2); // Result<Error | CustomError, number>