TypeScript 2.0 introduced the readonly modifier which can be added to a property or index signature declaration. It helps prevent against unintended property assignments. This lesson gives various use cases for readonly and shows what the generated JavaScript code looks like.

Normal use case for 'readonly':

interface User {
readonly id: nunber;
name: string
} class User { readonly id: number;
name: string;
constructor(
id: number, name: string
) {
this.id = id;
this.name = name;
}
}

Make a array readonly:

const level: ReadonlyArray<string> = [
'master',
'beginner'
];

[TypeScript] Make Properties and Index Signatures Readonly in TypeScript的更多相关文章

  1. [TypeScript] Type check JavaScript files using JSDoc and Typescript 2.5

    Typescript 2.5 adds JSDoc type assertion support for javascript file via ts-check service. First of ...

  2. [TypeScript] Deeply mark all the properties of a type as read-only in TypeScript

    We will look at how we can use mapped types, conditional types, self-referencing types and the “infe ...

  3. [TypeScript] Query Properties with keyof and Lookup Types in TypeScript

    The keyof operator produces a union type of all known, public property names of a given type. You ca ...

  4. [TypeScript] Transform Existing Types Using Mapped Types in TypeScript

    Mapped types are a powerful and unique feature of TypeScript's type system. They allow you to create ...

  5. [TypeScript] Create Explicit and Readable Type Declarations with TypeScript mapped Type Modifiers

    Using the optional “+” sign together with mapped type modifiers, we can create more explicit and rea ...

  6. [TypeScript] Model Alternatives with Discriminated Union Types in TypeScript

    TypeScript’s discriminated union types (aka tagged union types) allow you to model a finite set of a ...

  7. [Typescript Kaop-ts] Use AOP in Vue Components with TypeScript and Kaop-ts

    Aspect Oriented Programming, AOP, allows to reuse logic across an entire app in a very neat way, dec ...

  8. [TypeScript] Restrict null and undefined via Non-Nullable-Types in TypeScript

    This lesson introduces the --strictNullChecks compiler option and explains how non-nullable types di ...

  9. angular6 Can't bind to 'zzst' since it isn't a known property of

    文档: https://angular.io/guide/template-syntax#event-binding The Angular compiler may reject these bin ...

随机推荐

  1. Linux 基础入门二

    1.远程连接  ssh协议:secure shell  ~]# ss -tnl 查看系统是否监听在tcp协议的22号接口:  ~]# ip addr list 或者 ifconfig 查看ip地址 确 ...

  2. Java基础学习总结(17)——线程

    一.线程的基本概念 线程理解:线程是一个程序里面不同的执行路径 每一个分支都叫做一个线程,main()叫做主分支,也叫主线程. 程只是一个静态的概念,机器上的一个.class文件,机器上的一个.exe ...

  3. COGS——T 2478. [HZOI 2016]简单的最近公共祖先

    http://www.cogs.pro/cogs/problem/problem.php?pid=2478 ★☆   输入文件:easy_LCA.in   输出文件:easy_LCA.out   简单 ...

  4. [CSSinJS] Convert Sass (SCSS) Styled Button to CSSinJS with JavaScript Templates and Variables

    This is an introduction to CSSinJS that doesn't require any JavaScript knowledge, just a basic CSS. ...

  5. C语言:具体解释指针

    指针应该算得上是c语言的精华,但也是难点. 非常多教程或者博客都有对其具体的解说与分析. 我这一节的内容,也是解说指针.但我会尽量使用图解的方式,使大家非常easy理解及掌握. 一.基本使用 先来看看 ...

  6. elasticsearch搜索类型简单介绍

    简单搜索 GET请求很easy--你能轻松获取你想要的文档.让我们来进一步尝试一些东西.比方简单的搜索! 我们尝试一个最简单的搜索所有员工的请求: GET /megacorp/employee/_se ...

  7. 服务器性能监控tips

    一.tops 第一行 当前时间/已运行时间/登录用户数/最近 5 10 15分钟平均负载(平均进程数 cat /proc/loadavg) 除了前3个数字表示平均进程数量外,后面的1个分数,分母表示系 ...

  8. 16. IntellIJ IDEA 配置 Maven 以及 修改 默认 Repository

    转自:https://www.cnblogs.com/phpdragon/p/7216626.html 今天将IntellIJ IDEA 关于Maven的配置总结一下,方便以后可参考. IDEA版本: ...

  9. hbase启动报错:Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0

    输入HBASE_MASTER_OPTS只是为了快速寻找这个选项而已,如果你手工找也可以 刚才那个命令回车后直接跳到这 前面加#就好了 修改后保存.重新启动hbase就好了. 注意:各个节点都要修改哦. ...

  10. 【MySQL主从复制原理及搭建全过程】

    目录 准备工作 主从复制原理 开始搭建主从复制 本文将使用mariaDB数据库实现主从复制,其步骤与MySQL数据库无差异. MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护, ...