为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕妹3146593 2019-02-26 17:06:08
使用带有调用签名的对象字面量来定义泛型函数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请问需要怎么解决。
查看完整描述

2 回答

?
MMTTMM

TA贡献1869条经验 获得超4个赞

const myIdentityFn = identity;


查看完整回答
反对 回复 2019-02-26
?
慕森卡

TA贡献1806条经验 获得超8个赞

改成这样就好了

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


查看完整回答
反对 回复 2019-02-26
  • 2 回答
  • 0 关注
  • 1311 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号