Effect CommunityEC
Effect Community3y ago
11 replies
tomchristensen

Issue with Either.gen and type signature

Something seems to be broken with either the type signature or the implementation for Either.gen - to get an actual right result, you have to explicitly return yield an Either.right, but the type signature is the same if you just return a raw value.
import { Either } from 'effect'

// Type signature: Either.Either<"left", "right">
const eitherWithReturn = Either.gen(function* (_) {
  if (0 > 1) {
    yield* _(Either.left('left' as const))
  }
  return 'right' as const
})

// Type signature: Either.Either<"left", "right">
const eitherWithReturnYield = Either.gen(function* (_) {
  if (0 > 1) {
    yield* _(Either.left('left' as const))
  }
  return yield* _(Either.right('right' as const))
})

console.log(eitherWithReturn) // { _id: 'Either', _tag: 'Right', right: undefined }
console.log(eitherWithReturnYield) // { _id: 'Either', _tag: 'Right', right: 'right' }
Was this page helpful?