[TypeScript] Modifier
2024-10-21 17:21:47
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.
最新文章
- [Hadoop in Action] 第1章 Hadoop简介
- 从github拉取项目到myeclipse本地
- 我的Windows naked apps
- Java多线程同步的方法
- js 日期插件 datepicker
- Java代码编写规范(不是标准规范,自行整理,无须纠结)
- linux tar命令 压缩、打包、解压 详解
- JAVA中生成、解析二维码图片的方法
- IDEA写scala简单操作
- mybatis之Mybatis_demo
- Taro 多端开发的正确姿势:打造三端统一的网易严选(小程序、H5、React Native)
- Nginx 如何减轻高流量下的压力
- VKD224B触摸芯片调试笔记
- Ubuntu系统安装
- ADB 命令介绍
- python的闭包函数
- W-D-S-UART编程
- HUE配置文件hue.ini 的hbase模块详解(图文详解)(分HA集群和非HA集群)
- 【Linux】VirtualBox安装ubuntu排错LowGraphic
- [转]CNN 中千奇百怪的卷积方式大汇总