(function () { // 泛型:先用字符去指代未知类型 使用时 传入具体的类型 function fn3(x) { return x; } fn3(12); fn3("12"); // function fn4(x: T, y: K): number | string { // return x + y; // } function fn4(x, y) { return x + y; } function fn5(x, y) { return [x, y]; } fn5(3, '43'); const res = fn4(3, '23'); console.log(res, '22222'); // 严格按照接口格式传参 // 函数中泛型继承接口 function fn6(a) { return a; } fn6({ jump: 'aa' }); // 类中泛型继承接口 class Ending { constructor(name) { this.name = name; } } let e = new Ending({ jump: 'aa' }); })();