案例
interface InterfaceFn {
//
<T>(string:T):T
}
let getStr:InterfaceFn = <T>(str:T):T =>{
//
return str;
}
console.log(getStr('fxgetStr'));
console.log(getStr(123456));
// 泛型接口2
interface InterfaceFn2<T> {
(string:T):T
}
//
let getData = function<T>(str:T):T{
//
return str;
}
let getstr2:InterfaceFn2<string> = getData;
let getstr3:InterfaceFn2<number> = getData;
console.log(getstr2('1233-字符串'));
console.log(getstr3(1233));
网友评论