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; } }
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
vue-class-component : 调用类方法时 TS2339