Effect CommunityEC
Effect Community2y ago
8 replies
Steff

Error with SchemaTaggedError and Match: Effect.Effect<unknown, unknown, unknown>

When using SchemaTaggedError with Match, I got an Effect.Effect<unknown, unknown, unknown> see below:
class ProductStatus extends Schema.TaggedClass<ProductStatus>()("ProductStatus", {
  status: Schema.literal("inactive", "active"), 
  cancelledAt: Schema.nullable(Schema.DateFromSelf), 
}){}
class SomeSchemaTaggedError extends Schema.TaggedError<SomeSchemaTaggedError>()("SomeSchemaTaggedError", {}){}
class SomeDataTaggedError extends Data.TaggedClass('SomeDataTaggedError')<{
}> {}

//: Effect.Effect<unknown, unknown, unknown> | ProductStatus | SomeDataTaggedError
//Expected: SomeDataTaggedError | SomeSchemaTaggedError | ProductStatus
const op = pipe(
  Match.value(new ProductStatus({status: "active", cancelledAt: null})),
  Match.not(
    { status: "active" },
    (_) => new SomeDataTaggedError()
  ),
  Match.when(
    { cancelledAt: Match.instanceOf(Date) }, 
    (_) => new SomeSchemaTaggedError()
  ),
  Match.orElse(
    (ps) =>
      new ProductStatus({
        ...ps,
        status: "inactive", 
        cancelledAt: new Date(), 
        })
  )
);
Was this page helpful?