TypeScript:使用字符串名称创建对象

时间:2016-09-15 11:05:15

标签: javascript angular typescript

我正在使用装饰器方法按照excellent post关于按名称显示对象的问题来解决这个问题。代码编译,但我收到运行时错误。

我无法让链接到上面的页面上的游乐场执行:它只会导致一个about:blank。

这是我的装饰代码:

export function RegisterComponent(obj: ComponentType<GalleriaComponentBase>) {
    new ComponentRegistry().RegisterComponent(obj);
}

我尝试将我的@RegisterComponent装饰器应用到组件的基类,obj.name等于ComponentBase,这当然是没有用的。

所以,我尝试将装饰器应用于每个派生类,但是我收到以下运行时错误:

Argument of type 'typeof RepositoryComponent' is not assignable to parameter of type 'new () => ComponentBase'.

ComponentBase看起来像这样:

export class GalleriaComponentBase {
    refreshComponent() {};
    getCustomUserComponentTypeFriendlyName() {};
}

有人可以帮忙吗?

0 个答案:

没有答案
相关问题