首页 > 其他 > 详细

[TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types

时间:2017-03-06 21:02:28      阅读:189      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/Answer1215/p/6511592.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!