TS类型4

54 阅读1分钟
    Map对象: map数据结构是我最喜欢的数据结构,可以对他来对两次以上数组遍历的代码进行优化,降低代码时间复杂度, 深得我心!
    const map = new Map() // 
    map方法:
        clear() // 移除map对象中所哟键值对
        set() //
        get()
        has() // 返回一个boolean 用来判断map中是否包含键对应的值
        delete() // 删除map中的元素,删除成功返回true, 失败返回false
        size属性, 返回map中的键值对的数量
        keys() // 返回一个iterator对象, 包含了map中的每个元素的键
        values() // 返回新的iterator对象, 包含了map对象中的每个元素的值
        
        遍历: for( let [key, value] of newMap) {}
        
   元组: 一个数组中存储不同的类型的元素,元组可作为参数传递给函数
      [1, 'bog']
      
   联合类型:
       const val: string | number | string[]
       
   接口: 
       interface interName {
           firstName: string,
           lastName: string,
           sayHi: () =>string,
       }
   联合类型和接口:
       interface interName{
           program: string,
           command: string[] | string | (()=>string)
       }
       
  接口和数组:
      interface interfaceName {
          [index: string]: string,
      }
      
      const list: interfaceName = ['bob', 'gogle', 'sdn']
      
  接口继承: 
      interface Person {
          age: number
      }
      interface Music extends Person {
          name: string
      }
      
      const person: Music = {
          age: 23, name: 'an'
      }
      
      const person1 = <Musician>{}     person1.age = 33, persion.name = 'sun'
      
 多继承实例:
     interface parent1 {
         val1: number
     }
     
     interface parent2 {
         val2: number
     }
     
     interface Child extends parent1, parent2 {}
     const children: Child o= {val1: 23, val2: 323 }