Type Inference Issues with Pipe in TypeScript Effects
I know in the past that it has been sometimes recommended to avoid pipe due to inference problems, bud I didn't see any examples. Is the following an expected problem, or a different bug? Is there a type helper to combine a union of effects?
const Something = (a: number) => {
if (a > 0) return Effect.fail('bad')
return Effect.succeed({ yay: true } as const)
}
const something = Something(0)
// something: Effect.Effect<{ yay: true }> | Effect.Effect<never, 'bad', never>
// rather than: Effect.Effect<{ yay: true }, 'bad', never>
pipe(
something,
// Argument of type '<E, R>(self: Effect<never, E, R>) => Effect<unknown, unknown, unknown>' is not assignable to parameter of type '(a: Effect<never, string, never> | Effect<{ readonly yay: true; }, never, never>) => Effect<unknown, unknown, unknown>'.
// Types of parameters 'self' and 'a' are incompatible.
// Type 'Effect<never, string, never> | Effect<{ readonly yay: true; }, never, never>' is not assignable to type 'Effect<never, string, never>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
// Type 'Effect<{ readonly yay: true; }, never, never>' is not assignable to type 'Effect<never, string, never>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
// Type '{ readonly yay: true; }' is not assignable to type 'never'.
Effect.andThen((a) => {
// a: never
return a
})
)
// Works fine
Effect.andThen(something, (a) => a) const Something = (a: number) => {
if (a > 0) return Effect.fail('bad')
return Effect.succeed({ yay: true } as const)
}
const something = Something(0)
// something: Effect.Effect<{ yay: true }> | Effect.Effect<never, 'bad', never>
// rather than: Effect.Effect<{ yay: true }, 'bad', never>
pipe(
something,
// Argument of type '<E, R>(self: Effect<never, E, R>) => Effect<unknown, unknown, unknown>' is not assignable to parameter of type '(a: Effect<never, string, never> | Effect<{ readonly yay: true; }, never, never>) => Effect<unknown, unknown, unknown>'.
// Types of parameters 'self' and 'a' are incompatible.
// Type 'Effect<never, string, never> | Effect<{ readonly yay: true; }, never, never>' is not assignable to type 'Effect<never, string, never>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
// Type 'Effect<{ readonly yay: true; }, never, never>' is not assignable to type 'Effect<never, string, never>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
// Type '{ readonly yay: true; }' is not assignable to type 'never'.
Effect.andThen((a) => {
// a: never
return a
})
)
// Works fine
Effect.andThen(something, (a) => a)