我试图使用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/