【问题标题】:Angular Electron - showOpenDialog typescript errors? no properties in common with type 'OpenDialogOptions'Angular Electron - showOpenDialog 打字稿错误?没有与“OpenDialogOptions”类型相同的属性
【发布时间】:2020-06-19 09:40:22
【问题描述】:

我正在尝试使用 Electron 的本机对话框支持来打开文件,但我一直遇到这个我似乎无法解决的打字稿问题:

[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);
    });
  }
}

我可以做些什么来解决这个问题吗?

【问题讨论】:

    标签: angular typescript electron


    【解决方案1】:

    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);
        });
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 2019-07-03
      • 2021-02-19
      • 1970-01-01
      • 2017-12-22
      • 2017-03-26
      • 2023-01-25
      相关资源
      最近更新 更多