
Effect-TS Has a Free API That Most Developers Dont Know About
Effect is a powerful TypeScript library for building reliable applications with typed errors, concurrency, and dependency injection. Basic Effect import { Effect , Console } from " effect " ; const program = Effect . gen ( function * () { yield * Console . log ( " Starting... " ); const result = yield * fetchUser ( " 123 " ); return result ; }); Effect . runPromise ( program ); Typed Errors class UserNotFound { readonly _tag = " UserNotFound " ; } class NetworkError { readonly _tag = " NetworkError " ; } const fetchUser = ( id : string ): Effect . Effect < User , UserNotFound | NetworkError > => Effect . gen ( function * () { const res = yield * Effect . tryPromise ({ try : () => fetch ( `/api/users/ ${ id } ` ), catch : () => new NetworkError () }); if ( ! res . ok ) yield * Effect . fail ( new UserNotFound ()); return yield * Effect . tryPromise ({ try : () => res . json (), catch : () => new NetworkError () }); }); Dependency Injection import { Context , Layer } from " effect " ; cl
Continue reading on Dev.to Webdev
Opens in a new tab

