Using the optional “+” sign together with mapped type modifiers, we can create more explicit and readable type declarations. We can also use the “-” (minus) sign to remove optional declarations from properties.

For example, we have an interface:

interface IPet {
name: string;
age: number;
favoritePark?: string
}

There is two required props and one favoriatePark as optional prop.

From TypeScirpt 2.8, we are able to gereate a new interface based on existing one, and add or remove props:

For example we want to remove all the optional props, we can use '-':

interface IPetRequired {
[K in keyof IPET]-?: IPet[K]
}

'-': remove

'?': optional

'-?': remove optional

We can also use '+' to indicate what we have added:

type ReadonlyPet = {
+readonly [K in keyof IPet]?: IPet[K]
}

Here we added readonly type.

最新文章

  1. 21、ASP.NET MVC入门到精通——ASP.NET MVC4优化
  2. JSP之->初识JSP
  3. springMVC注解启用及优化
  4. C#预处理器指令 ,你造吗??? (●'◡'●)
  5. UIControl事件
  6. [转载] 一致性问题和Raft一致性算法
  7. 理解js闭包(二)
  8. vssettings 的备份和导入
  9. iTunes无法验证服务器“s.mzstatic.com.”的身份
  10. codevs 1183 泥泞的道路 (二分+SPFA+差分约束)
  11. UML建模之活动图介绍(Activity Diagram)
  12. c#关于EXCEL导出数据库的做法
  13. Android- assent和raw的区别
  14. postman接口测试系列:接口参数化和参数的传递
  15. salesforce零基础学习(八十五)streaming api 简单使用(接近实时获取你需要跟踪的数据的更新消息状态)
  16. 【CJOJ1372】【洛谷2730】【USACO 3.2.5】魔板
  17. SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页
  18. Java面向对象概述及三大特征(封装,继承和多态)
  19. mvn打包时添加日期参数
  20. Python print函数用法,print 格式化输出

热门文章

  1. [ 总结 ] Linux kickstart 无人值守安装系统构建过程
  2. [ kvm ] 进程的处理器亲和性和vCPU的绑定
  3. jQuery重置单选框和input框
  4. 【C++】类的特殊成员变量+初始化列表
  5. Selenium2+python自动化52-unittest执行顺序【转载】
  6. AC日记——平衡树练习 codevs 4244
  7. 使用 gulp 压缩 CSS
  8. python socket 连续send,出现粘包问题
  9. CocoaPods 2017最新、最快安装和使用说明
  10. NOIP2011选择客栈