使用场景:定义一个函数或类时,无法确定要使用的具体类型(返回值、参数、属性的类型不能确定) 泛型使用时相当于一个参数 functiondemo< T > ( arg:  T ) :  T { return  arg; 
} 
demo< number> ( 10 ) 
demo< string> ( '你好' ) 
demo ( true ) 
demo ( 10 ) 
interface  Param < A , B >  { title :  string, state :  A , list :  B [ ] 
} type ListType =  { name : string, age : number} 
const  p1 :  Param< boolean, ListType>  =  { title :  '泛型和接口结合使用' , state :  true , list :  [ { name : '张三' , age : 18 } , { name : '李四' , age : 16 } , ] 
} 
function  getLength< T  extends  {  length : number } > ( arg:  T ) :  number{ return  arg. length; 
} 
getLength ( [ 1 , 2 , 3 , '4' ] )  
getLength ( 'nihao' )  function  getLength< T  extends  string  |  any[ ] > ( arg:  T ) :  number{ return  arg. length; 
} 
getLength ( [ 1 , 2 , 3 , '4' ] )  
function  getLength< T > ( arg:  T [ ] ) :  number{ return  arg. length; 
} 
getLength< string |  number> ( [ '张三' , '李四' , 10 ] )  
class  MyClass < T > { prop :  T ; constructor ( prop :  T ) { this . prop =  prop; } 
} 
type User =  { name : string, age : number} 
const  user1 : User =  { name : '张三' , age : 18 } 
const  c1 =  new  MyClass < User> (  user1 ) 
const  c2 =  new  MyClass < string> ( '张三' )