【问题标题】:Electron issue after updating electron and typescript更新电子和打字稿后的电子问题
【发布时间】:2020-09-18 15:28:26
【问题描述】:

我有一个刚刚更新的小型电子项目(电子、打字稿等)...

这是破坏的代码:

dialog.showOpenDialog({}, (files) => {
    if(files && files.length > 0) {
      fs.readFile(files[0], 'utf8', (err, res) => {
        if (!err) {
          editor.setModel(monaco.editor.createModel(res, 'javascript'));
        }
      })
    }
  })

不喜欢dialog.showOpenDialog(后面的{}

我得到的错误是:

Argument of type '{}' is not assignable to parameter of type 'BrowserWindow'.

我该如何解决这个问题?

【问题讨论】:

    标签: node.js typescript electron


    【解决方案1】:

    showOpenDialog 的使用方式不同,可能是您从一个相当旧的电子版本更新,他们改变了它。现在它需要一个可选的 browserWindow 和一个 options 对象并返回一个 promise(显示为 async/await 语法):

      const {canceled, files, bookmarks} = await dialog.showOpenDialog({});
    

    参考:https://www.electronjs.org/docs/api/dialog#dialogshowopendialogbrowserwindow-options

    【讨论】:

      猜你喜欢
      • 2018-03-15
      • 1970-01-01
      • 2019-06-20
      • 2019-07-04
      • 2019-03-19
      • 2017-03-16
      • 2022-01-06
      • 2017-02-02
      • 2017-02-04
      相关资源
      最近更新 更多