1、泛型的概念
/* 泛型:任意类型 *///anyvar str1:any = 'hello'str1 = 2212// 劣势:放弃了类型检查// 即要任意类型又要类型检查// 1、有类型检查,只能放置特定数据类型function getData(msg:string){console.log(msg);}// 2、放弃了类型检查,但是能够传任意类型function test1(msg:any){console.log(msg);}test1(222)// 3、泛型,既有类型检查,又可以传任意类型,这也是泛型的好处所在function getMsg<T>(msg:T){console.log(msg);}getMsg<string>("hello")getMsg<number>(121)
