1. 泛型:任意类型
  2. 好处:兼顾了灵活性和类型检查

定义一个泛型函数

  1. function goTest<T>(s:T):T{
  2. console.log(s)
  3. return s
  4. }
  5. goTest<string>("hello")
  6. goTest<number>(10)
  7. goTest<object>({name:"cheng"})