Aljabr: I Brought Rust Enums to TypeScript (Again). This Time It's Actually Good.
Two years ago, I wrote a blog post called "I Was Bored So I Brought Rust Enums to TypeScript: A Tale of Questionable Life Choices". In it, I documented my descent into madness attempting to build a...

Source: DEV Community
Two years ago, I wrote a blog post called "I Was Bored So I Brought Rust Enums to TypeScript: A Tale of Questionable Life Choices". In it, I documented my descent into madness attempting to build a Rust-style Result<T, E> type in TypeScript. The result was… functional. Barely. It had issues. The tag was enumerable (which meant JSON.stringify would include it, breaking everything), the type inference was held together with duct tape, and honestly, I'm pretty sure it only worked because TypeScript felt sorry for me. I said I'd never do it again. I lied. Meet Aljabr (الجبر) Al-jabr is the Arabic word that gave us "algebra." It literally means "reunion of broken parts" or "bone-setting." I couldn't think of a more fitting name for a library that exists purely because I was bored and wanted to wrestle TypeScript into submission one more time. Aljabr is a TypeScript library for tagged unions (algebraic sum types, if you want to sound smart at parties) with exhaustive pattern matching.