zoukankan      html  css  js  c++  java
  • typescript

    相同点

    都可以描述一个对象或者函数

    都允许拓展(extends

     

    不同点

    type 可以声明基本类型别名,

    // 基本类型别名

     

    type Name = string

     

    // 联合类型

    interface Dog {

        wong();

    }

    interface Cat {

        miao();

    }

     

    type Pet = Dog | Cat

     

    // 具体定义数组每个位置的类型

    type PetList = [Dog, Pet]

     

    即type可以声明 基本类型,联合类型,元组 的别名,interface不行

     

    interface 能够声明合并

    interface User {

      name: string

      age: number

    }

     

    interface User {

      sex: string

    }

     

    /*

    User 接口为 {

      name: string

      age: number

      sex: string 

    }

    */

     

    TypeScript提供了从旧类型中创建新类型的一种方式 — 映射类型

    type Readonly<T> = {
        readonly [P in keyof T]: T[P];
    }
    type Partial<T> = {
        [P in keyof T]?: T[P];
    }

    type PersonPartial = Partial<Person>;
    type ReadonlyPerson = Readonly<Person>;
  • 相关阅读:
    ExtJs 4.0 ExtJs2.2 JavaScript
    C++中关于classview、resourceview、fileview
    BIN OBJ 区别
    数据编码
    多线程
    REST
    SQL Server 2005安装
    临时
    数据存储
    灰度直方图
  • 原文地址:https://www.cnblogs.com/lhs-fight/p/14300763.html
Copyright © 2011-2022 走看看