Forbid extending class from implementing a constructor

24 Views Asked by At

I have an abstract class Foo:

abstract class Foo {
  constructor() {
    // ...
  }
}

I don't want classes that extend Foo to be able to implement a new constructor:

class Bar {
  constructor() { // Error: can't implement a constructor
    super();
    console.log("hello from Bar's constructor!").
  }
}

How can I achieve this with typescript? private constructors forbid extension altogether. protected constructors allow custom constructors in extending classes.

0

There are 0 best solutions below