Effect CommunityEC
Effect Community2y ago
15 replies
mihaelkonjevic

Effect.all type inference fails with generic arguments

Hi, I have a weird case where using generic argument results in
unknown
when the argument is passed to Effect.all. Here are the examples:

In this example result is inferred as unknown[]:

function foo1<T extends Effect.Effect<string>>(input: T[]) {
    return Effect.gen(function* ($) {
        const result = yield* $(Effect.all(input));
        return result;
    });
}


In this example result is correctly inferred as string[], the only change was adding the .map call to the input argument

function foo2<T extends Effect.Effect<string>>(input: T[]) {
    return Effect.gen(function* ($) {
        const result = yield* $(
            Effect.all(input.map((v) => v.pipe(Effect.map((v) => v)))),
        );
        return result;
    });
}


If I don't use generics, result is also correctly inferred as string[]

function foo3(input: Effect.Effect<string>[]) {
    return Effect.gen(function* ($) {
        const result = yield* $(Effect.all(input));
        return result;
    });
}


Is there a better way to do this? I need to capture input's type because foo return value is dependant on whatever was passed in as the argument.

TypeScript version: 5.4.5
Effect version: 3.1.3
Was this page helpful?