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. Winscp远程连接Linux主机,上传和下载文件

    1.安装Winscp.这里不再赘述,网上搜索下载安装就可以 2.点击桌面Winscp快捷键,打开Winscp 3.在打开的页面上填写远程主机的IP,用户名和密码,点击保存,会在页面的左边出现一个站点, ...

  2. 通过C语言程序改动控制台的背景和前景颜色

    本文主要解说怎样通过C语言来改动dos背景和前景颜色.我们首先来看一下dos的背景颜色的属性. 打开開始菜单,点击执行,弹出执行对话框.输入cmd,回车. (打开dos控制台) 在命令提示符界面下,输 ...

  3. Android的矩阵(一):ColorMatrix

    最近的学习过程中看到关于android色彩矩阵的内容,以前看到这部分内容,基本都是跳过的,没有认真细读. 自己给自己找的借口是: 1,大一学的矩阵内容早就忘的干干净净了,当时学的时候就很烦人,所以现在 ...

  4. assert 的理解

    assert 可以实现如下功能: 保证参数之间的大小等约束关系: 函数执行过程中得到的中间结果是否符合预期: def gen_batch(batch_size, skip_window, num_sk ...

  5. UVALive - 6269 Digital Clock 模拟

    UVALive - 6269 Digital Clock 题意:时钟坏了,给你一段连续的时间,问你现在可能的时间是多少. 思路:直接模拟,他妈的居然这场就跪在了这题,卧槽,他妈的就在111行,居然多打 ...

  6. Python(十二) Pythonic与Python杂记

    一.导言 二.用字典映射代替switch case语句   # 字典代替 switch 语句 # switch () # { # case 0 : # dayName= 'a'; # break; # ...

  7. JWT 使用介绍

    转载收藏于 http://www.cnblogs.com/zjutzz/p/5790180.html JWT是啥? JWT就是一个字符串,经过加密处理与校验处理的字符串,形式为: A.B.C A由JW ...

  8. LG Gram 2018 z980 白

    因为今年8代处理器i5的双核变成了四核,感觉是个换电脑的好时机,本来打算买macbook,但是6月的发布会并没有发布,于是开始寻找一些比较有特点的笔记本电脑. 了解了这样一款笔记本 LG GRAM 1 ...

  9. python数据处理技巧一

    字符串赋值(传参)技巧 Python中一般的字符串赋值的方式如下: variable = "Test" print "I just [%s] unit"%var ...

  10. 在hive执行创建表的命令,遇到异常com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes

    今天在练习hive的操作时,在创建数据表时,遇到了异常 FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.ex ...