如何禁用 tslint 文件中的规则 "TS2322: Type 'WebSocketAction' is not assignable to type 'boolean'."

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

任何人都可以帮助我在 tslint 文件中禁用此规则吗? 我有这样的信息:

"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;
  }
}

&& 运算符需要 boolean,但 this.actionWebSocketAction,因此您会得到打字稿错误。

您可以使用双感叹号解决错误!!:

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