Conditional Typing Based on Error Properties in Effect Typescript Library

I have a Data.TaggedError class and i want to be able to have one of the props from the error type (cause) to be conditionally typed based on another error prop (fromRequest)

ie:
type ErrProps<FromRequest extends boolean = false> = {
  readonly message: string
  readonly isFromRequest: FromRequest
  readonly cause: FromRequest extends true 
    ? DomException<"AbortError" | "VersionError" | "ConstraintError">
    : DomException<"InvalidStateError" | "NotFoundError" | "TransactionInactiveError">
}


I do have this working with using generic parameter on the final Error class (see image)

export class IDBIndexCountError<FromRequest extends boolean>
  extends Data.TaggedError("IDBIndexCountError")<
    IndexErrorProps<"count", FromRequest>
  > 
{}


Im doing this because ideally i dont want 2 separate error classes ,ie IndexCountError and IndexCountRequestError, it would just make the end API more confusing imo. However i still want to keep that dx where type of cause can be constrained inside of a conditional on isFromRequest to get better hints on the cause.name

Question is:

if this is something that effect supports?
All my types and tests seem to be working but ive also been suggested NOT to use generics type args in effect classes, but im not sure if that was more for Services and Contexts?
image.png
Was this page helpful?