Difference in inferred and explicit return types in TypeScript functions

import { Either } from "effect"

function something1(bool: boolean) {
  if(bool) {
    return Either.left(new Error())
  } else {
    if(bool) {
      return Either.right(Either.left(new Error()))
    }
  
    return Either.right(Either.right(bool))
  }
}

function something2(bool: boolean): Either.Either<Either.Either<boolean, Error>, Error> {
  if(bool) {
    return Either.left(new Error())
  } else {
    if(bool) {
      return Either.right(Either.left(new Error()))
    }
  
    return Either.right(Either.right(bool))
  }
}

Return type of something1:
Either.Either<never, Error> | Either.Either<Either.Either<never, Error>, never> | Either.Either<Either.Either<false, never>, never>


Return type of something2:
Either.Either<Either.Either<boolean, Error>, Error>


Why is the return type of something1 not the same as return type of something2? I'd like it if I didn't have to manually annotate the return type like something2.
Was this page helpful?