[TS] Class Properties Public, Private and Read Only Modifiers

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[TS] Class Properties Public, Private and Read Only Modifiers相关的知识,希望对你有一定的参考价值。

In the constructor, we want to set the prop to readonly, you need to do like this:

class Superhero {
   
    readonly name: string

    constructor(
        name: string,
        editor: string,
        createdYear: number
    ) {

            name = this.name;
    }
}

 

以上是关于[TS] Class Properties Public, Private and Read Only Modifiers的主要内容,如果未能解决你的问题,请参考以下文章

[Vue + TS] Use Properties in Vue Components Using @Prop Decorator with TypeScript

2-1-12 TS Class

vue-class-component : 调用类方法时 TS2339

覆盖单个 Spring Boot 测试的属性

找不到插件“proposal-class-properties”[重复]

TypeScript 专题之 Ts 中的类(class)