New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fluent-type-results

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluent-type-results

FluentTypeResults is a lightweight Typescript library built to solve a common problem - returning an object to either indicate success or failure of an operation instead of using exceptions.

  • 1.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 05 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc