ts初学.md 456 B

ts基础

interface接口定义

  1. 用来更好的定义数据集合,为每一项进行准确的定义
  2. 用法

    1. interface定义必须包含label属性,并且值类型为string

      
      interface LabelledValue {
      label: string;
      }
      
      function printLabel(labelledObj: LabelledValue) {
      console.log(labelledObj.label);
      }
      
      let myObj = {size: 10, label: "Size 10 Object"};
      printLabel(myObj);