zoukankan      html  css  js  c++  java
  • [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.

  • 相关阅读:
    03-模板引擎
    C#扩展方法
    DataTable转IHashObjectList
    创建DataTable
    02-一般处理程序基础
    css3相关样式
    css样式
    css基础知识
    表单和HTML5
    表格相关知识
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11694123.html
Copyright © 2011-2022 走看看