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

Viewed 913

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

screenshot

1 Answers

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