2025年2月18日

泛型工具

摘要: // 泛型工具 interface user { name: string age: number sex: string } interface rUser { name?: string age?: number sex?: string } // Partial<泛型> 把所有属性改为可选属性 阅读全文

posted @ 2025-02-18 23:54 ChoZ 阅读(17) 评论(0) 推荐(0)

协变、逆变、双向协变

摘要: interface a { name: string } interface b { name: string, age: number } let A:a = { name: '222' } let B:b = { name: '112', age: 88 } // 协变,a作为主类型,b是作为副 阅读全文

posted @ 2025-02-18 17:07 ChoZ 阅读(7) 评论(0) 推荐(0)

typeof、is

摘要: // 收缩类型:判断是不是属于某个类型 // 使用typeof只对基础类型有效 // const isNum = (num:any) => typeof num 'number' // 使用instanceof可以对引用类型进行区分 const isArrary = (arr:any) => arr 阅读全文

posted @ 2025-02-18 15:26 ChoZ 阅读(6) 评论(0) 推荐(0)

Proxy、Reflect

摘要: // Proxy是es6新增的拦截器,总共拦截十三种,代理 // Reflect是反射,跟Proxy的方法一样是十三种,对应的参数一模一样 // Proxy是代理引用类型,对象、数组、map、set、函数 let person = {name:'bai',age:14} const personPr 阅读全文

posted @ 2025-02-18 13:47 ChoZ 阅读(29) 评论(0) 推荐(0)

set、map、weakSet、weakMap

摘要: // set:天然去重属性,引用类型除外 const s:Set<number> = new Set([1,2,2,3]) // console.log(s); //1,2,3 s.add(4) // 添加 s.delete(1) // 删除 s.has(2) // 判断是否有2 s.clear() 阅读全文

posted @ 2025-02-18 12:14 ChoZ 阅读(21) 评论(0) 推荐(0)

导航