[TypeScript] Modifier
TypeScript 2.8 adds the ability for a mapped type to either add or remove a particular modifier. Specifically, a readonly or ? property modifier in a mapped type can now be prefixed with either + or - to indicate that the modifier should be added or removed.
type MutableRequired<T> = { -readonly [P in keyof T]-?: T[P] }; // Remove readonly and ?
type ReadonlyPartial<T> = { +readonly [P in keyof T]+?: T[P] }; // Add readonly and ?
Example:
type MutableRequired<T> = T extends object ? {-readonly [K in keyof T]: T[K]} : T;
interface Book {
readonly name: String;
}
const newState: MutableRequired<Book> = {
name: 'st'
};
newState's anme is mutable and required.
[TypeScript] Modifier的更多相关文章
- Typescript 查缺补漏
Types Casting: let input = xxx as HTMLInputElement; let input = <HTMLElement>xxxx; Object Shap ...
- typescript类(学习笔记非干货)
我们声明一个 Greeter类.这个类有3个成员:一个叫做greeting的属性,一个构造函数和一个greet方法. We declare a Greeter class. This class ha ...
- [TypeScript] Collect Related Strings in a String Enum in TypeScript
As of TypeScript 2.4, it is now possible to define string enums, or more precisely, enums with strin ...
- [TypeScript] Make Properties and Index Signatures Readonly in TypeScript
TypeScript 2.0 introduced the readonly modifier which can be added to a property or index signature ...
- [TypeScript] Sharing Class Behavior with Inheritance in TypeScript
Typescript classes make inheritance much easier to write and understand. In this lesson we look into ...
- TypeScript 参数属性
假设类中创建的 readonly 类型的属性,该类型的属性只能在声明处或构造器中进行初始化. class Octopus { readonly name: string; readonly numbe ...
- 用 F# 手写 TypeScript 转 C# 类型绑定生成器
前言 我们经常会遇到这样的事情:有时候我们找到了一个库,但是这个库是用 TypeScript 写的,但是我们想在 C# 调用,于是我们需要设法将原来的 TypeScript 类型声明翻译成 C# 的代 ...
- 基于Typescript和Jest刷题环境搭建与使用
写在前面 前几个月在公司用vue3和ts写项目,想巩固一下基础,于是我想起了去年基于JavaScript和Jest搭建的刷题环境,不如,给它搞个加强版,结合Typescript和Jest 搞一个刷题环 ...
- TypeScript: Angular 2 的秘密武器(译)
本文整理自Dan Wahlin在ng-conf上的talk.原视频地址: https://www.youtube.com/watch?v=e3djIqAGqZo 开场白 开场白主要分为三部分: 感谢了 ...
随机推荐
- 经典例题(Python)
经典例题 if嵌套 1.用户输入账号2.用户输入密码3.判断用户的账号是不是alex4.如果账号是alex在继续判断密码是不是alexdsb5.账号和密码都正确提示用户alex就是一个dsb6.如果账 ...
- 【C#】上机实验九
1. 设计一个Windows登陆窗体应用程序,能够实现根据现有表中数据模拟登陆,并设置相关属性,具体界面如下. 可能使用到的类: (1)SqlConnection (2)SqlCommand (3)S ...
- MGR并行复制从节点复制线程死锁
1.故障现象 20191113-22:32 datax全量同步t_shop_info表到 eorder所在的实例,t_shop_info表有两个唯一约束.总数据量不超过1w行,同步完成后MGR从库复制 ...
- 用JS实现输出两个数范围内的随机数
const rs = require("readline-sync"); function roundNum(min = 0, max = 0) { if (!isNaN(min) ...
- 6.transform?animation?区别?animation-duration【CSS】
1.Transform:它和width.left一样,定义了元素很多静态样式实现变形.旋转.缩放.移位及透视等功能,通过一系列功能的组合我们可以实现很炫酷的静态效果(非动画). 2.Animatio ...
- Oracle 11g 物理存储结构
Oracle 系统的物理存储结构比较具体和直观,它用来描述 Oracle 数据在磁盘上的物理组成情况.Oracle 系统的数据在逻辑上存储在表空间中,而在物理上存储在表空间所包含的物理文件(即数据文件 ...
- live555的使用(转载)
Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现 了对多种音视频编码格式的音视频数据的流 ...
- iview Carousel 轮播图自适应宽高;iview 轮播图 图片重叠问题;iview tabs 高度互相影响问题;vue this问题;
最终效果图: 一.轮播图中图片自适应宽高: <Carousel loop v-bind:height="imgHeight+'px'" v-model="caro ...
- Python JSON的简单使用
1 json简介 1.1 json是什么? JSON(JavaScript Object Notation)是一种轻量级的数据交换格式. “在JSON出现之前,大家一 ...
- OpenStack是什么,OpenStack详解
1. OpenStack是什么 OpenStack官方的解释很官方,而且从不同角度,也有不同的理解,OpenStack可以理解为一个云操作系统 OpenStack旗下包含了一组由社区维护的开源项目,他 ...