摘要: 泛型接口 console.log('#######泛型接口'); (() =>{ /* 在定义接口时,为接口的属性或者方法定义泛型类型 在使用接口时,再指定具体的泛型类型 */ //需求:定义一个类来存储用户的相关信息(id,名字,年龄) //通过一个类的实例对象来调用相关(add)的方法可以添加多 阅读全文
posted @ 2021-04-07 15:32 前端那点事 阅读(892) 评论(0) 推荐(0)
摘要: (() =>{ function getMsg<K,V>(value1:K,value2:V) :[K,V]{ return [value1,value2] } const arr1 = getMsg<string,number>('jack',100) console.log(arr1); con 阅读全文
posted @ 2021-04-07 11:42 前端那点事 阅读(134) 评论(0) 推荐(0)
摘要: ts泛型 (() =>{ // function getArr(value:number,count:number) :number[]{ // let arr =[] // for(let i=0; i<count; i++){ // arr.push(value) // } // return 阅读全文
posted @ 2021-04-07 11:21 前端那点事 阅读(44) 评论(0) 推荐(0)
摘要: 函数的重载 //函数的名字相同,函数的参数和个数不同 //需求:有一个add函数,他可以接受2个sting类型的参数进行拼接,也可以接受2个number类型的参数进行相加 //函数重载声明 function add(x:string,y:string) :string function add(x: 阅读全文
posted @ 2021-04-07 10:41 前端那点事 阅读(799) 评论(0) 推荐(0)
摘要: 可选参数 /* 1.如果什么都不传,则返回默认的 2.如果只传入姓氏,则返回姓氏 3.如果传入的姓氏和名字就返回姓名 */ const fullName = function(firstName:string='东方',lastName?:string){ if(lastName){ return 阅读全文
posted @ 2021-04-07 10:10 前端那点事 阅读(2053) 评论(0) 推荐(0)
摘要: 函数的完整写法 //1.函数声明写法 //小括号后面的:number代表的是返回值 function add(x:number,y:number) :number{ return x+y } const result = add(1,2) console.log(result); //2.函数表达式 阅读全文
posted @ 2021-04-07 09:31 前端那点事 阅读(683) 评论(0) 推荐(0)