Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript bug around empty parameters #6

Closed
theogravity opened this issue Feb 14, 2023 · 1 comment
Closed

Typescript bug around empty parameters #6

theogravity opened this issue Feb 14, 2023 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@theogravity
Copy link

theogravity commented Feb 14, 2023

Given this example:

import { createInterprocess } from '../interprocess';

export const { ipcMain: utilsIpcMain, ipcRenderer: utilsIpcRenderer } = createInterprocess({
  main: {
    /**
     * Returns the electron application version
     */
    async getElectronVersion() {
      return '1.0.0';
    },
  },
  renderer: {
    /**
     * Prints a log message in the frontend console.
     * The first parameter is always an IPC event object.
     */
    async logMessage(_, _msg: string) {
      return;
    },
  },
});

If I want to implement the invoker directly to the context bridge:

import { contextBridge } from 'electron';
import { utilsIpcRenderer } from '../ipc/handlers/utils.ipc';

const api = {
  utils: {
    // typescript complains about the first parameter even though the handler is defined without any params
    // so I have to satisfy it by using undefined
    getElectronVersion: () => utilsIpcRenderer.invoke.getElectronVersion(undefined),
    onLogMessage: (callback) => {
      utilsIpcRenderer.handle.logMessage(async (_, { data: msg }) => {
        callback(msg);
      });
    },
  },
};

try {
  contextBridge.exposeInMainWorld('native', api);
} catch (error) {
  console.error(error);
}

image

  • I'm using Typescript 4.9.5
  • I'm not using the package installed as an npm module but copied the src files to my project to get around sandbox: true limitations
@daltonmenezes daltonmenezes self-assigned this Feb 14, 2023
@daltonmenezes daltonmenezes added bug Something isn't working enhancement New feature or request labels Feb 14, 2023
@daltonmenezes
Copy link
Owner

Hi @theogravity , could you please test the #8 PR?

daltonmenezes added a commit that referenced this issue Feb 14, 2023
fix: type issue on invokers with zero arguments - fixes #6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants