typescript 窗口['angularComponentReference']显示类型错误

fgw7neuy  于 2022-12-14  发布在  TypeScript
关注(0)|答案(1)|浏览(104)

我正在尝试在一个Angular 项目上使用NgZone:

constructor(
   private fishboneService: FishboneService,
   private zone: NgZone,
) {
  window['angularComponentReference'] = {
    zone: this.zone, 
    componentFn: (value: any) => this.getDataFromOutside(value), 
    component: this
  };
  console.log('reference added');
}

但我得到以下错误:
元素隐式具有“any”类型,因为索引表达式不是“number”类型。
19窗口['Angular 组件引用'] = {

sqxo8psd

sqxo8psd1#

您可以在代码前面加上ts-ignore。请参阅https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-6.html#suppress-errors-in-ts-files-using--ts-ignore-comments

// @ts-ignore
window['angularComponentReference'] =

相关问题