Bug: asyncAndThrough not declared in IResult interface
Problem
Both Ok and Err implement asyncAndThrough, but it is not declared in the IResult interface.
// src/result.ts
interface IResult<T, E> {
// ...
andThrough<R>(f: (t: T) => R): Result<T, ...> // ✅ declared
asyncAndThen<U, F>(f): ResultAsync<U, E | F> // ✅ declared
asyncMap<U>(f): ResultAsync<U, E> // ✅ declared
// asyncAndThrough — ❌ MISSING
}
class Ok<T, E> implements IResult<T, E> {
asyncAndThrough<F>(f: (t: T) => ResultAsync<unknown, F>): ResultAsync<T, E | F> // implemented
}
class Err<T, E> implements IResult<T, E> {
asyncAndThrough<F>(_f: (t: T) => ResultAsync<unknown, F>): ResultAsync<T, E | F> // implemented
}
Why it matters
IResult is the authoritative API contract for Result. If asyncAndThrough is not in the interface:
- Documentation gap — Users reading
IResult to understand the API won't discover asyncAndThrough
- Contract inconsistency — The interface is the spec; implementing a method without declaring it in the interface is a design inconsistency
- Subclass risk — Anyone extending
Ok or Err and relying on IResult as a guide would miss this method
The pattern is already broken for asyncAndThrough specifically
IResult declares asyncAndThen and asyncMap (the async equivalents of andThen and map), so the expectation is that asyncAndThrough (the async equivalent of andThrough) should also be declared there.
Fix
Add asyncAndThrough to the IResult interface:
interface IResult<T, E> {
// ... existing methods ...
andThrough<R extends Result<unknown, unknown>>(f: (t: T) => R): Result<T, InferErrTypes<R> | E>
andThrough<F>(f: (t: T) => Result<unknown, F>): Result<T, E | F>
// Add this:
asyncAndThrough<R extends ResultAsync<unknown, unknown>>(
f: (t: T) => R,
): ResultAsync<T, InferAsyncErrTypes<R> | E>
asyncAndThrough<F>(f: (t: T) => ResultAsync<unknown, F>): ResultAsync<T, E | F>
}
Consistency Table
| Method |
In IResult |
In Ok |
In Err |
andThrough |
✅ |
✅ |
✅ |
asyncAndThen |
✅ |
✅ |
✅ |
asyncMap |
✅ |
✅ |
✅ |
asyncAndThrough |
❌ |
✅ |
✅ |
Bug:
asyncAndThroughnot declared inIResultinterfaceProblem
Both
OkandErrimplementasyncAndThrough, but it is not declared in theIResultinterface.Why it matters
IResultis the authoritative API contract forResult. IfasyncAndThroughis not in the interface:IResultto understand the API won't discoverasyncAndThroughOkorErrand relying onIResultas a guide would miss this methodThe pattern is already broken for
asyncAndThroughspecificallyIResultdeclaresasyncAndThenandasyncMap(the async equivalents ofandThenandmap), so the expectation is thatasyncAndThrough(the async equivalent ofandThrough) should also be declared there.Fix
Add
asyncAndThroughto theIResultinterface:Consistency Table
IResultOkErrandThroughasyncAndThenasyncMapasyncAndThrough