angular - Angular Electron -showOpenDialog typescript 错误?没有与 'OpenDialogOptions'类型相同的属性

标签 angular typescript electron

我试图使用Electron的 native 对话框支持来打开文件,但我一直遇到这个 typescript 问题,但似乎无法解决:

[ts] Type '(folderPath: any) => void' has no properties in common with type 'OpenDialogOptions'.

这是我的代码:
import { ElectronService } from 'ngx-electron'

export class ChartOfAccountsComponent implements OnInit {


public electronDialog = new ElectronService().remote.dialog;

openImport() {
    let properties: any = {
      title: "Import budget",
      properties: ['openDirectory']
    }

    this.electronDialog.showOpenDialog(properties, (folderPath) => {
      if (folderPath === undefined){
          console.log("You didn't select a folder");
          return;
      }
      console.log('folderPath', folderPath);
    });
  }
}

我有什么办法可以解决这个问题?

最佳答案

showOpenDialog返回OpenDialogReturnValue的类型:

  interface OpenDialogReturnValue {
    /**
     * whether or not the dialog was canceled.
     */
    canceled: boolean;
    /**
     * An array of file paths chosen by the user. If the dialog is cancelled this will
     * be an empty array.
     */
    filePaths: string[];
    /**
     * An array matching the `filePaths` array of base64 encoded strings which contains
     * security scoped bookmark data. `securityScopedBookmarks` must be enabled for
     * this to be populated. (For return values, see table here.)
     *
     * @platform darwin,mas
     */
    bookmarks?: string[];
  }
您想要的是这样的:
this.electronDialog.showOpenDialog(properties, (value: OpenDialogReturnValue) => {
      if (value.canceled){
          console.log("You didn't select a folder");
          return;
      }
      console.log('folderPaths', value.filePaths);
    });

关于angular - Angular Electron -showOpenDialog typescript 错误?没有与 'OpenDialogOptions'类型相同的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60567689/

相关文章:

Angular4 Content-Security-Protocol 拒绝加载字体

javascript - Karma 单元测试中的错误 'Cannot read property ' triggerEventHandler' of null'

angular - 当其中之一具有异步管道时,如何在两个条件下实现 和 ngif

node.js - Electron 应用程序未启动

带有解析器的 Angular 7 路由不会加载组件

javascript - angular2 一旦使用填写搜索表单,如何在刷新页面后获取查询参数?

javascript - 无法将图像高度和宽度分配给 typescript 中的输入类型框

Angular mat-select-search可重用下拉组件,如何控制传递的对象数组和控制函数执行?

javascript - 无法将一个脚本导入另一个脚本

node.js - “npm install electron”也下载 Chrome 吗?