Home > Blockchain >  How to infer default generic parameter from a function type?
How to infer default generic parameter from a function type?

Time:07-09

How could I extract the function's default type parameter to get something like this statement to compile?

const fails: string = "" as ReturnType<<T = string>() => T>;

CodePudding user response:

ReturnType<<T = string>() => T> is unknown and not string:

type F = <T = string>() => T;

type X = ReturnType<F>;
// type X = unknown            
  • Related