Enhancing `ApiError` Type with `_tag` Property in TypeScript Using `effect/schema`

I'm using the effect/schema package to parse an ApiError response from my backend. I have defined the following:
export const _ApiErrorSchema = S.struct({
  message: S.string,
  info: S.object,
  code: S.number,
  timestamp: S.string,
  requestId: S.string,
});

export interface ApiError
  extends S.Schema.Type<typeof _ApiErrorSchema> {}

export const ApiErrorSchema: S.Schema<ApiError> = _ApiErrorSchema;

However, I would also like to add a _tag: 'ApiError' property to the resulting POJO object of type ApiError allowing it to be matched with other errors on _tag:
{
  _tag: 'ApiError'
  message: string,
  info: object,
  code: number,
  timestamp: string,
  requestId: string,
} satisfies ApiError

How do I accomplish this? I tried simply adding this to the ApiError, but then I get a compile error on ApiErrorSchema.
Was this page helpful?