Typescript abstract optional method

You can do this with class and interface merging:

interface Foo {
   print?(l: string): void;
}

abstract class Foo {
  abstract baz(): void;

  foo() {
    this.print && this.print('foo');
  }
}

class Bar extends Foo {
  baz(): void {
    if (this.print) {
      this.print('bar');
    }
  }
}

Link to the above code in the Typescript playground

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)