I have a factory-like function that is meant to return an sub-class instance of BaseApi
. It currently looks something like this (trimmed out irrelevant parts):<
What you actually want is new() => T
, since you intend to use the argument as a constructor and produce a T
. Even if you could write typeof T
, that wouldn't be what you want, since T
might not have a zero-argument constructor.
Remember that the typeof
operator takes a value and produces a value. T
is already a type; it is not a value.
Naturally, this is addressed in the TypeScript FAQ https://github.com/Microsoft/TypeScript/wiki/FAQ#why-cant-i-write-typeof-t-new-t-or-instanceof-t-in-my-generic-function