Javascript 角度2:具有多个依赖项的组件
以下代码:Javascript 角度2:具有多个依赖项的组件,javascript,typescript,angular,Javascript,Typescript,Angular,以下代码: ... @Component({ selector: 'sitelink', properties: ['route: route, title: title, isHome: home, href: href'] }) @View({ template: '' }) export class SiteLink { constructor(@Optional() @Host() @SkipSelf() parentFrame: AppFrame, @Optional(
...
@Component({
selector: 'sitelink',
properties: ['route: route, title: title, isHome: home, href: href']
})
@View({
template: ''
})
export class SiteLink {
constructor(@Optional() @Host() @SkipSelf() parentFrame: AppFrame, @Optional() @Host() @SkipSelf() parentLink: SiteLink) {
}
...
在从TypeScript到JavaScript的转换过程中,给出了以下错误
at line 32, file app-frame.ts Argument of type 'typeof SiteLink' is not assignable to parameter of type 'Type'.
Component({
selector: 'sitelink',
properties: ['route: route, title: title, isHome: home, href: href']
})
at line 36, file app-frame.ts Argument of type 'typeof SiteLink' is not assignable to parameter of type 'Type'.
View({
template: ''
})
仅使用一个构造函数参数即可正常工作。从参数列表中删除注释时,它也不起作用。删除@组件
和@视图
注释后,代码将编译。因此,错误必须与@组件
注释有关。
编辑:即使我用另一种类型(例如AppFrame)替换SiteLink参数,也会得到相同的错误
我正在使用alpha 36和DefiniteTypedRepository中最新的d.ts文件。通过使用前向引用,可以在构造函数中插入类本身的实例:
constructor(@Inject(forwardRef(() => SiteLink)) siteLink) {
this.name = nameService.getName();
}
有关更多详细信息,请参阅。正如Jesse Good所写,angular的d.ts文件存在此问题,请参阅 替换
interface Type extends Function {
new(args: any): any;
}
与
给我修好了。我不确定你想做什么是可能的。在
SiteLink
的构造函数中,您正在调用类本身。您确定这就是您想要的吗?是的,我想要获取父“SiteLink”组件。错误可能与此相同。您使用的是什么版本的typescript?是的,这可能是问题所在。我正在使用atom typescript插件,它应该始终使用最新版本。这并不能解决问题。即使我用另一种类型替换SiteLink参数,也会得到相同的错误。
interface Type extends Function {
new(...args): any;
}