Understanding the Use of `filterOrElse` in TypeScript Code Example

I guess I missed the point of filterOrElse or I am misusing it. I have something like:
  registerCustomer: (paymentCustomer) =>
    maybeReconcileMollieCustomerBySlugifiedName(paymentCustomer.name).pipe(
      Effect.filterOrElse(
        (existingCustomer) => existingCustomer.id !== null,
        () => createMollieCustomer(paymentCustomer),
      ),
    ),


Where maybeReconcileMollieCustomerBySlugifiedName returns Effect.Effect<{id: string | null}, ..., ...> and createMollieCustomer returns Effect.Effect<{id: string}, ..., ...>
I would have expected the filterOrElse method to be able to strip the
null
from the inferred return type. But it's not the case.

Am I supposed to use Effect.if and return the value with a non-null assertion ? πŸ€”

Like this is doing what I want but fils unadapted:
registerCustomer: (paymentCustomer) =>
  maybeReconcileMollieCustomerBySlugifiedName(paymentCustomer.name).pipe(
    Effect.flatMap((existingCustomer) =>
      Effect.if(existingCustomer.id !== null, {
        onTrue: Effect.succeed({ id: existingCustomer.id! }),
        onFalse: createMollieCustomer(paymentCustomer),
      }),
    ),
  ),
Was this page helpful?