Effect CommunityEC
Effect Community3y ago
4 replies
Rory

Interaction between generators and type narrowing

Interesting quirky interaction between generators and type narrowing. Generators are fail fast but the compiler doesn't understand that. You can return after the yield so the compiler understands, though not sure if its the right thing to do here
if (foo === undefined || foo === null) {
    yield* _(Effect.fail(new FooError('bad data')));
    // compiler still thinks foo is nully
    // however, adds '| undefined' to A
    return;
    // this fixes A but is it right?
    return yield* _(Effect.fail(new FooError('bad data')));
}
Was this page helpful?