3
我的TypeScript v2.2。TypeScript:anonymouse類工廠
我有這個類工廠:
export class A { name: string; }
export function makeConstructor(name: string)
{
const newClass = class extends A { };
newClass.prototype.name = name;
return newClass;
}
打字稿扔錯誤:
Return type of exported function has or is using private name '(Anonymous class)'.
我可以說,這個工廠返回any
隱藏的錯誤,但我怎麼能解釋什麼回報?
我試着寫
makeConstructor<T extends A>(name: string): T
makeConstructor<T extends typeof A>(name: string): T
makeConstructor<T extends A['prototype']>(name: string): T['prototype']
此代碼[作品](http://www.typescriptlang.org/play/#src=export%20class%20A%20 %7B%20name%3A%20string%3B%20%7D%0D%0A%0D%0Aexport%20function%20makeConstructor(名稱%3A%20string)%0D%0A%7B%0D%0A%20%20const%20newClass% 20%3D%20class%20extends%20A%20%7B%20%7D%3B%0D 0A%%0D 0A%%20%20newClass.prototype.name%20%3D%20name%3B%0D 0A%%0D% 0A%20%20return%20newClass%3B%0D%0A%7D)TypeScript 2.1 ... – Paleo