TS2339:类型“窗口”上不存在属性“ *”。仅在WebStorm中

时间:2018-11-02 03:33:34

标签: typescript webstorm

Win 10 Pro 64位

WebStorm:2018.2.3

错误:

enter image description here

enter image description here

在我的interfaces.ts文件中:

declare global {
  interface Window {
    dataLayer?: Array<any>;
    gtag?: (...args) => void;
    ga?: (action: string, type: string, data: Object) => void;
  }
}

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

const eventName = 'event';
const handlerName= doAction;
const target = ( <any>window ); // <===== THIS IS THE WORK AROUND

target.ga && target.ga(eventName, handlerName)