
Effect-TS Has a Free Functional API That Makes TypeScript Bulletproof
Effect-TS brings structured concurrency, typed errors, dependency injection, and resource management to TypeScript — all in one coherent system. Core: The Effect Type import { Effect , pipe } from ' effect ' ; // Effect<Success, Error, Requirements> const program : Effect . Effect < string , Error , never > = pipe ( Effect . succeed ( 42 ), Effect . map ( n => n * 2 ), Effect . flatMap ( n => n > 50 ? Effect . succeed ( `Big number: ${ n } ` ) : Effect . fail ( new Error ( ' Too small ' )) ) ); // Run it Effect . runPromise ( program ). then ( console . log ); Typed Errors (No More try/catch Guessing) class NotFoundError { readonly _tag = ' NotFoundError ' ; } class ValidationError { readonly _tag = ' ValidationError ' ; constructor ( readonly message : string ) {} } const getUser = ( id : number ): Effect . Effect < User , NotFoundError | ValidationError > => pipe ( Effect . succeed ( id ), Effect . flatMap ( id => id < 0 ? Effect . fail ( new ValidationError ( ' ID must be positive '
Continue reading on Dev.to JavaScript
Opens in a new tab



