2

I am new to typescript, when I type: (dialog is imported from a library)

ipcMain.handle("openDialog", (event, method, config) => {
  return dialog[method](window, config);
});

It is working in javascript but it throws Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Dialog' in typescript.
After finding some solutions online, none of them can solute this error for me.
That is what I have now:

ipcMain.handle("openDialog", (event : any, method : keyof Electron.Dialog, config : any) => {
  return dialog[method](window, config);
});

and I only got:

This expression is not callable.
  Each member of the union type '{ (browserWindow: BrowserWindow, options: CertificateTrustDialogOptions): Promise<void>; (options: CertificateTrustDialogOptions): Promise<...>; } | ... 6 more ... | { ...; }' has signatures, but none of those signatures are compatible with each other.

Any solutions?

SonMooSans
  • 95
  • 1
  • 4
  • It's hard to say anything without a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), but the reason why it's probably not working is that not all properties of `dialog` can be called with `(window, config)` becasue they, for example, aren't even a function. –  Apr 29 '22 at 11:19
  • `method: keyof Electron.Dialog` tells typescript that `method` is a property of `Electron.Dialog`, but that doesn't mean `method` must be a function. –  Apr 29 '22 at 11:21
  • It is a small electron project and I use that for opening dialog from the renderer. The main problem is even using `keyof typeof dialog`, it still throw an error. That is hard to show up all codes including config files... – SonMooSans Apr 29 '22 at 11:23
  • Maybe I can cast it to a function – SonMooSans Apr 29 '22 at 11:25
  • Does this question help you https://stackoverflow.com/questions/71887374/methodof-type-cannot-be-used-to-call-the-method – kelsny Apr 29 '22 at 13:48

0 Answers0