typescript给window对象添加属性

631 阅读1分钟
  1. 创建 vue.d.ts
interface Window {
  Vue: any;
}
  1. 在 ts 文件中使用
let vue = window.Vue

3.导入其他文件的情况

import { StoreOptions } from "../interface/store.interface";
interface Window {
  Vue: any;
}

使用window.Vue的地方就会报错

修改为:

import { StoreOptions } from "../interface/store.interface";
declare global {
  interface Window {
    customProp: string;
    Vue: any;
  }
}