interface GenericIdentityFn {
<T>(arg: T): T;
}
function identity<T>(arg: T): T {
return arg;
}
let myIdentity: GenericIdentityFn = identity;
新手目前正在学ts,但是一直不明白为什么接口已经定义了参数的类型,function里还要再写一遍?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你可以这么写
你在定义
identity时并没表示这个函数是实现了GenericIdentityFn的,所以你得自己写一遍类型参数。实际上
function xxx() {}的写法也无法声明其实现了什么