11

While designing a definition file, I came across this error (TS2507).

How can I specify a type to be a 'constructor function type' ?

Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101

2 Answers2

20

If you are defining an interface, you can declare that it is a constructor like such:

interface SomeInterface {
  new(someParam: any): SomeInterface
}

This is useful when you are defining typings for already existing JS libraries. See this SO answer for more details.

Community
  • 1
  • 1
JKillian
  • 18,061
  • 8
  • 41
  • 74
-1

well, if you take a look at the original definition of the error (https://github.com/Microsoft/TypeScript/blob/master/tests/baselines/reference/classExtendingPrimitive.errors.txt) you'll see that the 'undefined' is hardcoded within this error message. And undefined was never a valid constructor type (even in js). So, I guess you don't need to do anything but ensure that you pass a valid constructor and not undefined resp. null. An example for such a problem can be found here: https://www.codecademy.com/forum_questions/52f67024282ae3a0890009b0

PlasmaLampe
  • 129
  • 2
  • 12