Created
February 1, 2025 11:44
-
-
Save jpb06/13e2dc32127921608f58a48fdfbcce8c to your computer and use it in GitHub Desktop.
Effects channels types extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Effect, Layer, pipe } from 'effect'; | |
| import { TaggedError } from 'effect/Data'; | |
| type EffectResultRequirement< | |
| T extends (...args: any) => Effect.Effect<unknown, unknown, unknown>, | |
| > = Effect.Effect.Context<ReturnType<T>>; | |
| type EffectResultSuccess< | |
| T extends (...args: any) => Effect.Effect<unknown, unknown, unknown>, | |
| > = Effect.Effect.Success<ReturnType<T>>; | |
| type EffectResultError< | |
| T extends (...args: any) => Effect.Effect<unknown, unknown, unknown>, | |
| > = Effect.Effect.Error<ReturnType<T>>; | |
| type EffectResultWithoutRequirement< | |
| T extends (...args: any) => Effect.Effect<unknown, unknown, unknown>, | |
| > = Effect.Effect<EffectResultSuccess<T>, EffectResultError<T>, never>; | |
| // -- | |
| class MyError extends TaggedError( | |
| 'my-error', | |
| )<{ | |
| cause?: unknown; | |
| message?: string; | |
| }> {} | |
| const program = () => Effect.fail(new MyError({ message: 'Oh no!' })); | |
| // Error = MyError | |
| type Error = EffectResultError<typeof program> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment