[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-tkinter使用方法——转载(一)
Tkinter图形界面设计(GUI) 转载URL:https://www.cnblogs.com/pywjh/p/9527828.html#lable [因为这是我第一个接触的GUI图形界面py ...
- lmir 随笔
近期需要研究一些特征工程的工作,就打算把微软之前公布出来的特征都复现一遍,今天遇到的特征是 LMIR, 其实也就是language model for information retrieval的简写 ...
- go 计算文件行
package main import ( "bufio" "fmt" "os" ) func main() { //判断命令行参数,小于两 ...
- 全栈项目|小书架|服务器开发-NodeJS 使用 JWT 实现登录认证
通过这篇 全栈项目|小书架|服务器开发-JWT 详解 文章我们对JWT有了深入的了解,那么接下来介绍JWT如何在项目中使用. 安装 $ npm install jsonwebtoken 生成 Toke ...
- “SQL Server does not exist or access denied.”
Have resolved the problem, the Port was different and so the Connection String now reads: <connec ...
- RabbitMQ实战
RabbitMQ消息队列 一.Hello World 1.amqp-client客户端依赖 2.Rabbitmq类与方法 二.交换机类型 Exchange Type 1.消息轮询分发(Round Ro ...
- element-ui 默认排序
table属性中,设置 :default-sort="{prop:'time', order:'descending'}" 1. prop为排序列,order为排列顺序 2. 多级 ...
- vue2.0项目在360兼容模式下打开空白
安装两个依赖环境 yarn add babel-polyfill -D yarn add babel-preset-es2015 babel-cli -D 在main.js中引入babel-polyf ...
- php文件路径处理函数
basename -- 返回路径中的文件名部分 # 语法 string basename ( string $path [, string $suffix ] ) //> 手册例子 echo & ...
- 安装License需要重启
"only commands for license handling are allowed in current state" Can you confirm if licen ...