DEV Community

Birowsky
Birowsky

Posted on

1

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay