Effect CommunityEC
Effect Community14mo ago
5 replies
Jambudipa

Working with the type of the payload on a TaggedRequest

I have the following type:
const SearchPayloadFields = {
  query: Schema.String,
  include: Schema.Boolean,
  plainText: Schema.Boolean,
  page: Schema.Number
} as const;

export class Search extends Schema.TaggedRequest<Search>()('Search', {
  failure: Schema.Never,
  success: Schema.Array(SearchResult),
  payload: SearchPayloadFields
}) {
}

const SearchPayloadSchema = Schema.Struct(SearchPayloadFields);
export type SearchQueryType = typeof SearchPayloadSchema.Type;

I would like to be able to infer the type of payload for use by the client side. This works, but seems overly verbose.

Is there a pattern for this?
Was this page helpful?