After some thought, I crafted a wrapper code block as follows:
type ConstructorToFunction<C extends {new (...args: any[])}>=
C extends { new (): infer Output } ? () => Output
: C extends { new (arg1: infer Arg1): infer Output } ? (Arg1) => Output
: C extends { new (arg1: infer Arg1, arg2: infer Arg2): infer Output } ? (Arg1, Arg2) => Output
// and so on
: never
const constructorToFunction = <C extends {new (...args: any[]): any}>(constructor: C): ConstructorToFunction<C> =>
(...args: []) => new constructor(...args)
The ConstructorToFunction
type transforms the constructor into a function with a matching structure, and constructorToFunction
acts as the actual intermediary passing arguments from the outer function to the constructor.
In practice, this can be applied like: constructorToFunction(Foo)
. It might not be the most elegant solution, but it certainly beats manually creating the wrapper, especially for constructors with multiple parameters.