How to force typescript not to use default when partial generic is used with constrain generic

Viewed 14

I got code like this:

const constrainGenericTest = <T extends string, F extends (arg: Parameters<F>) => number = (...args: any) => any>(
  fn: F
): F => {
  return fn;
};
constrainGenericTest<string>((arg: string) => arg)(1);

TypeScript doesn't show an error for calling function constrainGenericTest result with the wrong type, because always takes the default value of generic F. Is it possible to say TypeScript to get type from a function parameter instead of default value without specify second generic like that

constrainGenericTest<string, (arg: string) => number>((arg: string) => arg)(1);?

0 Answers
Related