Typescript generics call the literal amount of the object of the signature to define the generic function error.

use the literal amount of the object with the call signature to define the generic function

interface IGenericIdentityFn1 {

}
function identity<T>(arg: T): T {
      return arg;
    }
const myIdentityFn: {<T>(arg: T): T} = identity;
const myIdentityFn2: IGenericIdentityFn1 = identity;

both of these methods report errors
ERROR:

callable-types: Type literal has only a call signature-use < T > (arg: t) = > T instead

could you tell me how to solve it?

May.14,2022

const myIdentityFn = identity;

just change it to this

const myIdentityFn: < T > (arg: t) = > T = identity;


typescript 3.2.2 No pressure

Menu