还需要把类传入,用于构造函数生成instance,感觉很不友好啊。
Animal.ts
import { Singleton } from "./Singleton"; export class Animal<T> extends Singleton<T> { public root: string = "animal"; }Beast.ts
import { Animal } from "./Animar"; export class Beast extends Animal<Beast> { public name = "beast 1"; constructor() { super(); this.root = "i am a beast"; } }Bird.ts
import { Animal } from "./Animar"; export class Bird extends Animal<Bird> { public name: string = "bird 1"; constructor(){ super(); this.root="i am a bird"; } }打印结果: