Parameter of type (arrow function) | (arrow function) is typed as never instead of union of both

Is const assertion an option for you? You can set your constant as const and you won’t have any type issues:

const cellDataFormater = {
  string: (x: string) => x,
  float: (x: number) => x,
  int: (x: number) => x,
  date: (x: string) => x,
  boolean: (x: string) => x,
} as const;

cellDataFormater['string']('toto'); // ok

Playground link

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top