[TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types
2024-08-31 20:37:49
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.
最新文章
- 图片的赖加载(lazyLoad)
- com.opensymphony.xwork2.ognl.OgnlValueStack] - target is null for setProperty(null, ";emailTypeNo";, [Ljava.lang.String;@6f205e]
- 动易CMS之标签管理
- [NOIP2015] 提高组 洛谷P2668 斗地主
- Oracle 11g r2 x64 中文乱码解决方案
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
- 关于配置php源代码管理环境的几点注意
- hdu 5442 Favorite Donut 后缀数组
- MySQL慢查询(一) - 开启慢查询
- 私人定制javascript中数组小知识点(Only For Me)
- Ffmpeg简介
- easynetq发布订阅demo实现注意事项
- Python爬虫入门教程 4-100 美空网未登录图片爬取
- Python第一天:你必须要知道的Python擅长领域以及各种重点学习框架(包含Python在世界上的应用)
- 一种使用 sprintf 导致死机的情况
- gitlab之一: gitlab安装配置使用
- go语言中goroute使用:=遇到的坑
- MAC下Xcode配置opencv(2017.3.29最新实践,亲测可行)(转)
- Android基础笔记(九)- 广播
- 【Git】Git与GitHub 入门