README.md
Package detail
ts-results
A typescript implementation of Rust's Result and Option objects.
readme
changelog
3.3.0
Big thank you to @petehunt for all his work adding stack traces to Err.
- Added a stackproperty to allErrobjects. Can be used to pull a stack trace
- Added toOptionandtoResultmethods for converting betweenOptionandResultobjects
v3.2.1
- Fix regression found in Issue#24
v3.2.0
- Fixes for Typescript 4.2
v3.1.0
Big thank you to @petehunt for all his work adding the Option type.
New Features
- Added new - Option<T>,- Some<T>, and- Nonetypes!- You should feel at home if you're used to working with Rust: - import { Option, Some, None } from 'ts-results'; const optionalNum: Option<number> = Some(3).map((num) => num * 2); if (optionalNum.some) { console.log(optionalNum.val === 6); // prints `true` } const noneNum: Option<number> = None; if (noneNum.some) { // You'll never get in here }
 
- Added new - Option.isOptionand- Result.isResulthelper functions.
Other Improvements
- Got to 100% test coverage on all code!
- Removed uses of @ts-ignore
v3.0.0
Huge shout out to @Jack-Works for helping get this release out. Most of the work was his, and it would not have happened without him.
New Features
- Ok<T>and- Err<T>are now callable without- new!
- No longer breaks when calling from node
- Tree-shakable when using tools like rollup or webpack
- Fully unit tested
- Added these helper functions:- Result.all(...)- Same as- Resultsfrom previous releases. Collects all- Okvalues, or returns the first- Errvalue.
- Results.any(...)- Returns the first- Okvalue, or all of the- Errvalues.
- Result.wrap<T, E>(() => ...)- Wraps an operation that may throw an error, uses try / catch to return a- Result<T, E>
- Result.wrapAsync<T, E>(() => ...)- Same as the above, but async
 
- Deprecated elsein favor ofunwrapOrto prefer api parity with Rust
v2.0.1
New Features
- core: Added reaonly static EMPTY: Ok<void>;toOkclass.
- core: Added reaonly static EMPTY: Err<void>;toErrclass.
v2.0.0
This release features a complete rewrite of most of the library with one focus in mind: simpler types.
The entire library now consists of only the following:
- Two classes: Ok<T>andErr<E>.
- A Result<T, E>type that is a simple or type between the two classes.
- A simple Resultsfunction that allows combining multiple results.
New Features
- core: much simpler Typescript types
- rxjs: added new filterResultOkandfilterResultErroperators
- rxjs: added new resultMapErrTooperator
Breaking Changes
- core: ErrandOknow requirenew:- Before: let result = Ok(value); let error = Err(message);
- After: let result = new Ok(value); let error = new Err(message);
 
- Before: 
- core: mapfunction broken into two functions:mapandmapErr- before: result.map(value => "new value", error => "new error")
- after: result.map(value => "newValue").mapError(error => "newError")
 
- before: 
- rxjs: resultMapoperator broken into two operators:resultMapandresultMapErr- before: obs.pipe(resultMap(value => "new value", error => "new error"))
- after: result.pipe(resultMap(value => "newValue"), resultMapError(error => "newError"))
 
- before: 
 vultix
vultix