From a23edf36051f2147de6979ab5f185a86b4753e64 Mon Sep 17 00:00:00 2001 From: themodernhakr Date: Thu, 12 Jun 2025 00:37:01 -0500 Subject: [PATCH] Fix error typing in AsyncDoEither --- package.json | 2 +- src/either.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 2bc54ec..fcaaf2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fp-lib", - "version": "1.0.2", + "version": "1.0.3", "description": "Zero-dependency functional programming library optimized for Bun", "main": "dist/index.js", "module": "dist/index.js", diff --git a/src/either.ts b/src/either.ts index 3d05cc7..fcba02e 100644 --- a/src/either.ts +++ b/src/either.ts @@ -216,7 +216,6 @@ export class AsyncDoEither, E> { f: (scope: T) => Either | Promise>, ): AsyncDoEither, E> { const newPromise = this.promise.then(async (currentEither) => { - // Propagate Left case as is if (currentEither._tag === 'Left') { return currentEither as Either, E> } @@ -225,18 +224,15 @@ export class AsyncDoEither, E> { try { const nextEither = await f(scope) - // Propagate Left from bound computation if (nextEither._tag === 'Left') { return nextEither as Either, E> } - // Extend scope with new value return right({ ...scope, [key]: nextEither.right, }) as Either, E> } catch (err) { - // Handle unexpected exceptions return left(err as E) } }) @@ -255,7 +251,7 @@ export class AsyncDoEither, E> { if (either._tag === 'Left') { return either as Either } - return right(f(either.right)) + return right(f(either.right)) as Either }) } @@ -308,9 +304,12 @@ export class AsyncDoEither, E> { /** * Starts a new AsyncDoEither chain with an empty scope + * @typeParam E - The error type * @returns A new AsyncDoEither instance with an empty scope */ static start(): AsyncDoEither<{}, E> { - return new AsyncDoEither(Promise.resolve(right({}))) + // Fix: Create a Right value with explicit error type casting + const initial: Either<{}, E> = right({}) as Either<{}, E> + return new AsyncDoEither(Promise.resolve(initial)) } }