Mapped Types in Schema

I am not sure if this is even possible in schema, but would be interested to hear from an effect pro if there is a way of doing this:

I have a mapped type that links a specific tag to a specific handler function in a record like so:

export type Handlers = {
  [K in Event['_tag']]: (event: Extract<Event, { _tag: K }>) => void;
};


Now I have a generic record that I would like to parse with Schema to verify this structure. Note that the handler function would be called with the event that matches the tag and not a generic event.

Is that possible to do in Schema? If not would there be a way to separately parse key and handler to arrive at the desired structure and type? Thanks in advance!
Was this page helpful?