typescript 泛型调用签名的对象字面量来定义泛型函数报错

使用带有调用签名的对象字面量来定义泛型函数

interface IGenericIdentityFn1 {

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

这里两种方式都报错
ERROR:

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

请问需要怎么解决。

阅读 4k
3 个回答
const myIdentityFn = identity;

改成这样就好了

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