1.0.11 • Published 4 years ago

fluent-type-results v1.0.11

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

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 Package

npm i fluent-type-results

Example

It is assumed that the web api always returns a Result<Account> response.

import Axios from 'axios';
import Result from 'fluent-type-results';
import IAccount from './dto/IAccount';

export async function getUserAccount(id: number): Promise<IAccount | null> {
    const { data } = await Axios.get<Result<IAccount>>(`/account/${id}`);

    if (data.isFailed) {
        console.log(data.toErrorString);
    }

    // value is always null if the result has failed and will otherwise contain the value
    return data.value;
}

Important notes

  • Compared to FluentResults, a Result.Ok() function always requires a valid object to be passed with it.

Articles

Credits

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago