quick-lint-js

Find bugs in JavaScript programs.

E0295: abstract fields cannot have default values

TypeScript abstract fields in classes cannot have initializers. It is a syntax error to write an initializer for a field marked abstract:

abstract class Expression {
  abstract readonly op: string = "???";

  left!: Expression;
  right!: Expression;

  toString(): string {
    return `${this.left} ${this.op} ${this.right}`;
  }

  abstract eval(): any;
}

class AddExpression {
  readonly op: string = "+";

  eval(): any {
    return this.left.eval() + this.right.eval();
  }
}

To fix this error, remove the initializer:

abstract class Expression {
  abstract readonly op: string;

  left!: Expression;
  right!: Expression;

  /* ... */
}

Alternatively, keep the initializer but remove the abstract keyword:

abstract class Expression {
  readonly op: string = "???";

  left!: Expression;
  right!: Expression;

  /* ... */
}

Introduced in quick-lint-js version 2.10.0.

Documentation for other errors