DEV Community

Birowsky
Birowsky

Posted on

Why is this param type not assignable to the designated?

I'm trying to implement the suggestion here, specifically, this function:

function eventAssigner<Handlers extends Record<keyof Handlers, (e: any) => any>,
  Discriminant extends keyof any>(
  handlers: Handlers,
  discriminant: Discriminant
) {
  return <Key extends keyof Handlers>(
    event: Record<Discriminant, Key> & (Parameters<Handlers[Key]>[0])
  ): ReturnType<Handlers[Key]> => handlers[event[discriminant]](event);
}

However, eventAssigner is rejecting the…

Top comments (0)