function sayHello<T>(msg: T): T {
return msg;
}
// 指定泛型调用
sayHello<string>("你好世界");
// 运用类型推断缩写
sayHello("你好世界");
class MyClass<T> {
name: T;
constructor(name: T) {
this.name = name;
}
}
interface Inter {
length: number;
}
function fun3<T extends Inter>(a: T): number {
return a.length;
}