[TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types
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的更多相关文章
- [TypeScript] TypeScript对象转JSON字符串范例
[TypeScript] TypeScript对象转JSON字符串范例 Playground http://tinyurl.com/njbrnrv Samples class DataTable { ...
- Spark 学习笔记之 union/intersection/subtract
union/intersection/subtract: import org.apache.spark.SparkContext import org.apache.spark.rdd.RDD im ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- Java中的Union Types和Intersection Types
前言 Union Type和Intersection Type都是将多个类型结合起来的一个等价的"类型",它们并非是实际存在的类型. Union Type Union type(联 ...
- [Typescript] Typescript Enums vs Booleans when Handling State
Handling state with Typescript enums, instead of booleans, is preferred because:- Enums are more rea ...
- 编译TypeScript(TypeScript转JavaScript)
1.配置tsconfig.json文件 tsconfig.json文件配置说明 { "compilerOptions": { //生成相关说明,TypeScript编译器如何编译. ...
随机推荐
- [Python] The get() method on Python dicts and its "default" arg
# The get() method on dicts # and its "default" argument name_for_userid = { 382: "Al ...
- magento getCarriers 分析
完整的设置订单追踪信息的时候我们可能会用到它.在后台中他在这里设置: 有的时候我们想要设置自己定义的 carrier 比如 顺丰 申通 圆通 ..等等 我们能够先从 magento api 入手分析 ...
- rocketmq事务消息入门介绍
说明 周五的时候发了篇:Rocketmq4.3支持事务啦!!!,趁着周末的时候把相关内容看了下,下面的主要内容就是关于RocketMQ事务相关内容介绍了. 说明: 今天这篇仅仅是入门介绍,并没有涉及到 ...
- python缩进报错
1.这个错误应该已经好久了:也应该熟悉了才对 IndentationError: unexpected indent python 缩进错误:意外缩进Python 但今天的问题有点特殊,我想在程序中间 ...
- (错误记录)Vue: Unknown custom element
错误: vue.js:634 [Vue warn]: Unknown custom element: <ve-pie> - did you register the component c ...
- 好记性不如烂笔头——datagridview相关
DataGridViewTextBoxColumn dgv_IDY = new DataGridViewTextBoxColumn(); dgv_IDY.Visible = false; dgv_ID ...
- Maven学习总结(16)——深入理解maven生命周期和插件
在项目里用了快一年的maven了,最近突然发现maven项目在eclipse中build时非常慢,因为经常用clean install命令来build项目,也没有管那么多,但最近实在受不了乌龟一样的b ...
- OC学习篇之---Foundation框架中的其他类(NSNumber,NSDate,NSExcetion)
1.NSNumber 这个类主要是用来封装基本类型的,说到这里,就不得不说一下了: OC中的集合是不允许存入基本类型的,所以NSNumber类就诞生了,需要将基本类型封装一下,然后存进去,这个类似于J ...
- 【Codeforces Round #440 (Div. 2) A】 Search for Pretty Integers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先枚举一个数字的情况. 再枚举两个数的情况就好. [代码] #include <bits/stdc++.h> #defi ...
- Java与模式:装饰(Decorator)模式
装饰模式使用被装饰类的一个子类的实例.把client的调用委派到被装饰类,装饰模式的关键在于这样的扩展是全然透明的. 装饰模式在Java种使用也非常广泛,比方我们在又一次定义button.对话框等 ...