Using TypeScript v2.2.
In my codebase, there exists a class factory:
export class A { name: string; }
export function makeConstructor(name: string)
{
const newClass = class extends A { };
newClass.prototype.name = name;
return newClass;
}
However, TypeScript is throwing an error:
The return type of the exported function is referencing a private name '(Anonymous class)'.
To avoid this error, I could simply use any
as the return type. But how can I accurately describe what this factory function returns?
I've experimented with different approaches like:
makeConstructor<T extends A>(name: string): T
makeConstructor<T extends typeof A>(name: string): T
makeConstructor<T extends A['prototype']>(name: string): T['prototype']