简体   繁体   English

TypeScript:构造函数属性已声明但从未使用

[英]TypeScript: Constructor Property is declared but never used

currently studying and new to TypeScript.目前正在学习并且是 TypeScript 的新手。

I am trying to create a class and using a constructor to initiate private variables inside this class, however, I get hit with a [property name] is declared but never used .我正在尝试创建一个 class 并使用构造函数在这个 class 中启动私有变量,但是,我遇到了[property name] is declared but never used

export class CloClient extends Client {
    private identity: string[];
    private commands: { [name: string]: typeof CommandClass };
    private behaviors: { [name: string]: typeof Behavior };

    constructor(identity: string[], options: ClientOptions) {
        super(options);
        
        this.identity = identity;

        this.commands = {};
        this.behaviors = {};
    }
}

Using TypeScript 4.4.3, any suggestions?使用 TypeScript 4.4.3,有什么建议吗?

That warning will be displayed for all properties which are declared but are never accessed.对于声明但从未访问过的所有属性,将显示该警告。

Typescript is trying to inform you that in its current state, that property does not need to exist as it is never used during the execution of the script. Typescript 试图通知您,在其当前的 state 中,该属性不需要存在,因为它在脚本执行期间从未使用过。

Once you access / read from the property than this warning will disappear.一旦您访问/读取该属性,此警告就会消失。 ie some thing like:即像这样的东西:

if(this.identity){
... other code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM