Creating a Generic Response Layer

Trying to figure out how to make my Response Layer generic. We parse our JSON responses to ensure they conform to our schemas, so each one is differnt. Looking at how to represent that in a single context
type ParsedResponse<T extends Record<string, unknown> = never> = Omit<
  NextApiResponse,
  'json'
> & {json: (obj: T) => void}
export interface NextApiResponseService<T extends Record<string, unknown>> {
  readonly response: ParsedResponse<T>
}

export const NextApiResponseService = Context.Tag<NextApiResponseService>(// <-- this requires a generic, but not sure how to get it one

  '@home/NextApiResponseService',
)
Was this page helpful?