try/catch in TypeScript is such a gigantic pain in the ass. Even worse if used in Node, holy hell...

This page summarizes the projects mentioned and recommended in the original post on /r/typescript

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • Is there a way to make the compiler aware that it's running in Node? I did set the target according to the Node target mapping.

  • fawait

    A javascript library for making await more functional

  • Checkout fawait. It helps a bit. Not with typing the error, but it does help

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • node

    Node.js JavaScript runtime ✨🐢🚀✨

  • Node fs library

  • await-to-js

    Async await wrapper for easy error handling without try-catch

  • I've seen a nearly identical utility library called await-to-js but that's what I was going to suggest as well as the pattern does make error handling a lot easier and less nested.

  • proposal-pattern-matching

    Pattern matching syntax for ECMAScript

  • Also considering how Javascript works I don't see an end to this dilemma any time soon. You actually made me look up pattern matching for typescript again, and apparently there is a pretty nice looking tc39 proposal now, compared to the last time I looked it up. Combining this with an either type or something like that could save some headaches, although the issue with exceptions being thrown by every library still remains. The language is still evolving afterall and the course it's been taking lately is looking good. It can only get better.

  • proposal-record-tuple

    ECMAScript proposal for the Record and Tuple value types. | Stage 2: it will change!

  • Agreed, and using `Object.freeze` everywhere is a poor man's substitution for immutability by default. I'm cautiously optimistic about the tuples and records proposal but it could still take a while. In particular, I'm interested in what the TypeScript team can introduce to take advantage of those.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts