打字符:如何扩展两个类?
我想节省时间,并在扩展PIXI类(2d webGl渲染器库)的类之间重用通用代码。
对象接口:
module Game.Core {
    export interface IObject {}
    export interface IManagedObject extends IObject{
        getKeyInManager(key: string): string;
        setKeyInManager(key: string): IObject;
    }
}
我的问题是里面的代码不会改变,我想重用它,而不是复制它,这是实现:getKeyInManagersetKeyInManager
export class ObjectThatShouldAlsoBeExtended{
    private _keyInManager: string;
    public getKeyInManager(key: string): string{
        return this._keyInManager;
    }
    public setKeyInManager(key: string): DisplayObject{
        this._keyInManager = key;
        return this;
    }
}
我想做的是通过 管理器中使用的键自动添加,以在其属性中引用对象本身内部的对象。Manager.add()_keyInManager
因此,让我们以纹理为例。这是TextureManager
module Game.Managers {
    export class TextureManager extends Game.Managers.Manager {
        public createFromLocalImage(name: string, relativePath: string): Game.Core.Texture{
            return this.add(name, Game.Core.Texture.fromImage("/" + relativePath)).get(name);
        }
    }
}
当我这样做时,我希望该方法调用一个方法,该方法将存在于 返回的对象上。在本例中,此对象将是:this.add()Game.Managers.Manageradd()Game.Core.Texture.fromImage("/" + relativePath)Texture
module Game.Core {
    // I must extend PIXI.Texture, but I need to inject the methods in IManagedObject.
    export class Texture extends PIXI.Texture {
    }
}
我知道这是一个接口,不能包含实现,但我不知道该写什么来在我的类中注入类。知道 、 等需要相同的过程。IManagedObjectObjectThatShouldAlsoBeExtendedTextureSpriteTilingSpriteLayer
我在这里需要有经验的TypeScript反馈/建议,它必须有可能做到,但不是通过多次扩展,因为当时只有一个可能是可能的,我没有找到任何其他解决方案。