【问题标题】:Error compiling typescript with Vue.js TS2352使用 Vue.js TS2352 编译打字稿时出错
【发布时间】:2020-01-17 23:21:59
【问题描述】:

这是我的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'.

【问题讨论】:

    标签: typescript vue.js webpack


    【解决方案1】:

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

    const browserWindow = window as unknown as BrowserWindow
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-18
      • 2016-08-21
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 2018-08-12
      • 1970-01-01
      相关资源
      最近更新 更多