You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
Hi,
I am wondering if a similar issue or feature already exists. I am looking to create a Typescript type that accepts only valid electron events. For instance the BrowserWindow.on(event, listener) , I'm looking for a list of all of the valid events for .on. Something like
type AllBrowserWindowOnEvents = {
'always-on-top-changed': (e: Event, isAlwaysOnTop: boolean) => void;
'app-command: (e: Event, command: string) => void;
...and all of the other events, except I don't want to type them out
};
Does such a type already exist?
I tried things like:
type BrowserWindowOnEvents = Parameters<InstanceType<typeof Electron.BrowserWindow>['on']>[0];
but that only ever gives me Intellisense for the last BrowserWindow.on event, which is 'will-resize'.
It does work if I have new BrowserWindow().on(''), the intellisense will provide a list of all the possible events, but I'm looking to use it in a type definition when I don't have an instance of BrowserWindow.
Hope that makes sense, I would be willing to maybe put something together maybe for Electron-Userland but want to make sure nothing already exists.
Thanks
Proposed Solution
A type that lists all of the valid events for various listeners, ie
but that only ever gives me Intellisense for the last BrowserWindow.on event, which is 'will-resize'.
TS doesn't support overloaded function args inferring, see microsoft/TypeScript#26591 (closed with won't fix status).
Proposed Solution
I'd like this to happen to workaround the declined microsoft/TypeScript#26591 TS's issue as I also have a need to narrow/extract the event args typing. But as far as I know TS declarations of @electron get generated from the docs which is not the same as manual typing.
Unfortunately due to how we generate our documentation we can either (a) leave things as they are which is great for intellisense and the way 99% of our users will consume the electron types or (b) change things to use generics and inference but in a way that let's TS code consume the event types as enums in a nice way.
Personally I don't see a good way of doing both and I think the obvious choice is to keep doing (a).
We publish electron-api.json with every release, if you want you can manually generate your own .d.ts file with custom enums / structs using that JSON api definition
Preflight Checklist
Problem Description
Hi,
I am wondering if a similar issue or feature already exists. I am looking to create a Typescript type that accepts only valid electron events. For instance the
BrowserWindow.on(event, listener)
, I'm looking for a list of all of the valid events for.on
. Something likeDoes such a type already exist?
I tried things like:
but that only ever gives me Intellisense for the last BrowserWindow.on event, which is 'will-resize'.
It does work if I have
new BrowserWindow().on('')
, the intellisense will provide a list of all the possible events, but I'm looking to use it in a type definition when I don't have an instance of BrowserWindow.Hope that makes sense, I would be willing to maybe put something together maybe for Electron-Userland but want to make sure nothing already exists.
Thanks
Proposed Solution
A type that lists all of the valid events for various listeners, ie
Such a thing could be generated using the Typescript Compiler API
Alternatives Considered
Something that already exists that I'm missing.
Additional Information
No response
The text was updated successfully, but these errors were encountered: