Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-errorflow

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-errorflow

A simple zero dependency TypeScript empowered implementation of an Either construct for improved control flow and error handling

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

TsErrorFlow

A one file, zero-dependency library for improved control flow and error handling in TypeScript. In fact, the entire code base is only 41 lines including comments. Inspired by the concepts of Railway Oriented Programming.

TsErrorFlow leverages Union Types, Intersection Types, User-Defined Type Guards to provide an intuitive and type safe developer experience for error handling.

Usage

TsErrorFlow allows you to represent the potential errors in your application domain using plain old javascript objects. This makes it easier to follow a more explicit coding style in which relevant information about things that went wrong can be passed simply and acted on, instead of relying on throwing Errors for control flow:

interface ParkingLotFullError = {
    tryAgainAt: Date;
}

interface Ticket {
    ticketNumber: string;
    issuedAt: Date;
}

function tryGetTicket(): Ticket | ParkingLotFullError {
    if (lotIsFull()) {
        return makeError({
            tryAgainAt: new Date()
        });
    } 

    // return an actual ticket
}

const ticketResponse = tryGetTicket();

if (isError<Ticket, ParkingLotFullError>(ticketResponse)) {
    // response is definitely an error and will only allow access of properties from ParkingLotFullError
} else {
    // response is definitely a ticket and will only allow access of properties from Ticket
}

FAQs

Package last updated on 01 May 2018

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