使用Vue.js TS2352编译打字稿时出错

时间:2019-09-17 06:21:14

标签: typescript vue.js webpack

这是我的window.ts

import Vue from 'vue'

interface BrowserWindow extends Window {
  app: Vue
}

const browserWindow = window as BrowserWindow
export default browserWindow

我在编译时不断收到此错误

TS2352: Conversion of type 'Window & typeof globalThis' to type 'BrowserWindow' may 
be a mistake because neither type sufficiently overlaps with the other. If this was intentional, 
convert the expression to 'unknown' first.
  Property 'app' is missing in type 'Window & typeof globalThis' but required in type 'BrowserWindow'.

1 个答案:

答案 0 :(得分:1)

如错误消息所述,将windows强制转换为unknown,然后强制转换为BrowserWindow

const browserWindow = window as unknown as BrowserWindow