Type Narrowing in TypeScript Generator Functions: An Example

Is there a way to do type narrowing in generator functions?
here's an example:
function demo(foo: string | undefined) {
  return Effect.gen(function* () {
    if (foo == null) {
      yield* Effect.fail(new RuntimeException());
    }
    return foo;
  });
}


This has type Effect.Effect<string | undefined, RuntimeException, never> where really it is actually Effect.Effect<string, ...>
Was this page helpful?