TypeScript has 'interface' and 'type', so when to use which?

interface hasName {
firstName: string;
lastName: string;
} interface hasAddress {
address: string
} type Player = (hasName & hasAddress) | null; let player: Player = {firstName: 'Joe', lastName: 'Jonse', address: 'USA'};

It is recommended that to use 'interface' to define the props that obj should have.

'type' is recommended to use when combine multi interfaces to descide a single object like what we show in example.

[TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types的更多相关文章

  1. [TypeScript] TypeScript对象转JSON字符串范例

    [TypeScript] TypeScript对象转JSON字符串范例 Playground http://tinyurl.com/njbrnrv Samples class DataTable { ...

  2. Spark 学习笔记之 union/intersection/subtract

    union/intersection/subtract: import org.apache.spark.SparkContext import org.apache.spark.rdd.RDD im ...

  3. [TypeScript] Model Alternatives with Discriminated Union Types in TypeScript

    TypeScript’s discriminated union types (aka tagged union types) allow you to model a finite set of a ...

  4. [TypeScript] Using Interfaces to Describe Types in TypeScript

    It’s easy to pass the wrong value to a function. Typescript interfaces are great because they catch ...

  5. [Typescript] What is a Function Type ? Function Types and Interfaces - Are They Related ?

    Function Type: type messageFn = (name: string) => string; function sayHello(name: string): string ...

  6. [TypeScript] Query Properties with keyof and Lookup Types in TypeScript

    The keyof operator produces a union type of all known, public property names of a given type. You ca ...

  7. Java中的Union Types和Intersection Types

    前言 Union Type和Intersection Type都是将多个类型结合起来的一个等价的"类型",它们并非是实际存在的类型. Union Type Union type(联 ...

  8. [Typescript] Typescript Enums vs Booleans when Handling State

    Handling state with Typescript enums, instead of booleans, is preferred because:- Enums are more rea ...

  9. 编译TypeScript(TypeScript转JavaScript)

    1.配置tsconfig.json文件 tsconfig.json文件配置说明 { "compilerOptions": { //生成相关说明,TypeScript编译器如何编译. ...

随机推荐

  1. Android系统如何管理自己内存的?

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 机缘巧合写下这篇博客,作为个人工作经验的总结,不足之处,随后补上. 安卓是基于Linux2.6内核的 ...

  2. Mysql多实例安装+主从复制+读写分离 -学习笔记

    Mysql多实例安装+主从复制+读写分离 -学习笔记 .embody{ padding:10px 10px 10px; margin:0 -20px; border-bottom:solid 1px ...

  3. arukas 的 Endpoint

    arukas 的 Endpoint 什么是端点 What is Endpoint arukas.io 的实例几乎每周都自动重新启动,当实例重新启动时,其端口会更改.IP地址和端口的平均寿命是一周,有时 ...

  4. FreeMarker template error: The following has evaluated to null or missing

    使用freemarker前端分页,报错: FreeMarker template error: The following has evaluated to null or missing 后端直接赋 ...

  5. Oracle 12C R2 on Linux 7.X Data Guard 搭建文档

    1.查看主机和数据库信息   [oracle@oracle1 ~]$ sqlplus / as sysdba   SQL*Plus: Release 12.2.0.1.0 Production on ...

  6. 00089_字节输出流OutputStream

    1.字节输出流OutputStream (1)OutputStream此抽象类,是表示输出字节流的所有类的超类.操作的数据都是字节,定义了输出字节流的基本共性功能方法: (2)输出流中定义都是写wri ...

  7. android Email总结文档

    目录:src\com.android.email.activity 一. Welcome.java 根据AndroidManifest.xml可知该文件为程序入口文件: 加载该文件时,查询数据库账户列 ...

  8. 关于DOM的有关总结

    1.获取DOM元素 document.getElementById()  通过id获取DOM元素 document.getElementsByClassName() 通过类名获取DOM元素 docum ...

  9. numpy 高阶函数 —— np.histogram

    np.diff(a, n=1, axis=-1):n 表示差分的阶数: >> x = np.array([1, 2, 4, 7, 0]) >> np.diff(x) array ...

  10. Altium Designer敷铜的规则设定

    InPolygon 这个词是铺铜对其他网络的设置,铺铜要离其他网络远点,因为腐蚀不干净会对 电路板有影响... 问题一:: 如下图所示,现在想让敷铜与板子边界也就是keepoutlayer的间距小一点 ...