简体   繁体   中英

How to disable rule in tslint file “TS2322: Type 'WebSocketAction' is not assignable to type 'boolean'.”

Can anybody help me to unable this rule in tslint file? I have such message:

"TS2322: Type 'WebSocketAction' is not assignable to type 'boolean'."

export class WebSocketData {

  public authorization: string;

  constructor(
    public action: WebSocketAction = null,
    public data: any = null,
    token: string = null
  ) {
    this.authorization = token ? `Bearer ${token}` : null;
  }

  public isValid(): boolean {
    return this.data && this.action;
  }
}

截屏

The && operator expects a boolean , but this.action is WebSocketAction , thus you get the typescript error.

You can resolve the error by using a double exclamation point !! :

  public isValid(): boolean {
    return this.data && !!this.action;
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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