FluentTypeResults
FluentTypeResults is a lightweight Result Pattern Typescript library built to solve a common problem - returning an object to either indicate success or failure of an operation instead of using exceptions.
FluentTypeResults is the Typescript version of FluentResults and uses the same syntax and works great together!
Feedback and pull requests are greatly appreciated!
Key Features
- Fully works with the Result class from FluentResults
- Storing multiple errors in one Result object
- Designing Errors/Success in an object-oriented way
- Storing the root cause chain of errors in a hierarchical way
Installation
npm i fluent-type-results
Example
It is assumed that the web api always returns a Result<Account>
response.
;;;: Promise<IAccount | null> {const data = await Axiosget<Result<IAccount>>`/account/`;if dataisFailedconsole;// value is always null if the result has failed and will otherwise contain the valuereturn datavalue;}
Important notes
- Compared to FluentResults, a Result.Ok() function always requires a valid object to be passed with it.
Articles
Credits
- Altman - For his awesome work on FluentResults