[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 开场白 开场白主要分为三部分: 感谢了 ...
随机推荐
- leetcode两数相加
题目描述:给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表 ...
- 系統启动直接进BIOS
- 直线DDA,直线和圆的Bresenham算法
// DDA.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<Windows.h> #include<g ...
- web项目服务器安装及配置(虚拟机centOS7)
一.安装VMware(如需) 1.首先下载VMware虚拟机,地址: https://www.vmware.com/products/workstation-pro/workstation-pro-e ...
- js点击按钮复制内容到粘贴板
复制内容到粘贴板,就是要选择需要复制的内容并执行document.execCommand("copy")命令: //复制内容到粘贴板 function copyToClipboar ...
- SQL统计部门人数,人数为0的部门也要显示出来
相同点:它们都以一张部门表(或类别表),其它表都有部门编号DepartmentID(类别编号) 案例一:一张表 select c.DepartmentID,c.DepartmentName, t.Nu ...
- 关于SpringBoot下template文件夹下html页面访问的一些问题
springboot整合了springmvc的拦截功能.拦截了所有的请求.默认放行的资源是:resources/static/ 目录下所有静态资源.(不走controller控制器就能直接访问到资源) ...
- NFS启动文件系统
NFS启动文件系统 一.软硬件平台 1.开发板:创龙AM3359核心板,网口采用RMII形式. 2.UBOOT版本:U-Boot-2016.05,采用FDT和DM. 3.交换芯片MARVELL的88E ...
- golang读写文件的几种方式
golang中处理文件有很多种方式,下面我们来看看. (1)使用os模块 先来看看如何查看文件属性 package main import ( "fmt" "os&quo ...
- NTP时间服务器+DHCP服务器的搭建
一.构建NTP时间服务器 ntp服务器监控端口UDP:123 安装ntp和ntpdate 命令:yum -y install ntp netdate 修改配置文件/etc/ntp.conf 启动nt ...