variant
boxed
variant | boxed | |
---|---|---|
5 | 6 | |
178 | 613 | |
- | 2.3% | |
0.0 | 8.4 | |
2 months ago | 2 days ago | |
TypeScript | TypeScript | |
Mozilla Public License 2.0 | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
variant
-
Building React Components Using Unions in TypeScript
Variant
-
ADTs in Typescript
When working in a TS codebase I'll lean on this variant library, which works pretty well as far as simple sum types go (v3 is great but not stable yet).
-
disc-union - (yet another) library for working with discriminated union types
About half-way through writing this library I discovered that Variant existed... and does a great job at doing the exact same things (and more). I might not have started if I knew about that, but I'm glad I did because it has been a great learning experience!
-
ts-pattern: pattern matching library for TypeScript, with smart type inference
Oddly enough, this feature alone has been a a big draw to Rust, Haskell and functional programming in general for me... so it's nice that there's libs filling the gap for TypeScript. Here's another one I haven't gotten around to trying yet either.
-
Tool to normalize types (specifically intersections)?
I had to solve this for a project of mine.
boxed
- Boxed: Functional Types and Utilities for TypeScript
-
The gotcha of unhandled promise rejections
I was happy when Promise became available, but in retrospect I'd wish we would have skipped ahead and gotten Observable (e.g: https://rxjs.dev/) instead to enable more powerful functionality and composition etc.
In Typescript dealing with rejection is also painful since rejection reasons can't be guaranteed to be Error even when you always take care of that. And it can't help you guarantee that you're handling all types of errors thrown. For that purpose I'm thinking of using https://github.com/supermacro/neverthrow#readme or https://swan-io.github.io/boxed.
- Boxed: Functional utility types and functions for TypeScript
-
I Avoid Async/Await
Agree that try/catch is verbose and not terribly ergonomic, but my solution has been to treat errors as values rather than exceptions, by default. It's much less painful to achieve this if you use a library with an implementation of a Result type, which I admin is a bit of a painful workaround, but worth it. I've recently been using: https://github.com/swan-io/boxed.
By far the greatest benefit is being able to sanely implement a type-safe API. To me, it is utter madness throwing custom extensions of the Error class arbitrarily deep in the call-stack, and then having a catch handler somewhere up the top hoping that each error case is matched and correctly translated to the intended http response (at least this seems to be a common alternative).
- Boxed: Utility Types for Functional TypeScript
What are some alternatives?
type-fest - A collection of essential TypeScript types
async - Easily run code asynchronously
TypeScript - TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
neverthrow - Type-Safe Errors for JS & TypeScript
ts-pattern - 🎨 The exhaustive Pattern Matching library for TypeScript, with smart type inference.
cofx - A node and javascript library that helps developers describe side-effects as data in a declarative, flexible API.
rescript-compiler - The compiler for ReScript.
async - Async utilities for node and the browser
htmx - </> htmx - high power tools for HTML
posterus - Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
redux-saga - An alternative side effect model for Redux apps
RxJS - A reactive programming library for JavaScript