Skip to content

Commit 381c54b

Browse files
authored
Fix TypeScript errors in menu.ts (electron-react-boilerplate#2416)
* Fix TypeScript errors in menu.ts Apparently, MenuItemConstructorOptions.selector is a Darwin-only attribute. TypeScript detects it and displays an error. To fix this error we can cast it to MenuItemConstructorOptions. * Fixed accidentally removed type definition * Fixed another accidentally removed type definition Seems good. * Edited as requested * Fixed lint error
1 parent 061579f commit 381c54b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

app/menu.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
MenuItemConstructorOptions
88
} from 'electron';
99

10+
interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions {
11+
selector?: string;
12+
submenu?: DarwinMenuItemConstructorOptions[] | Menu;
13+
}
14+
1015
export default class MenuBuilder {
1116
mainWindow: BrowserWindow;
1217

@@ -49,12 +54,11 @@ export default class MenuBuilder {
4954
}
5055

5156
buildDarwinTemplate() {
52-
const subMenuAbout: MenuItemConstructorOptions = {
57+
const subMenuAbout: DarwinMenuItemConstructorOptions = {
5358
label: 'Electron',
5459
submenu: [
5560
{
5661
label: 'About ElectronReact',
57-
// @ts-ignore
5862
selector: 'orderFrontStandardAboutPanel:'
5963
},
6064
{ type: 'separator' },
@@ -81,10 +85,9 @@ export default class MenuBuilder {
8185
}
8286
]
8387
};
84-
const subMenuEdit: MenuItemConstructorOptions = {
88+
const subMenuEdit: DarwinMenuItemConstructorOptions = {
8589
label: 'Edit',
8690
submenu: [
87-
// @ts-ignore
8891
{ label: 'Undo', accelerator: 'Command+Z', selector: 'undo:' },
8992
{ label: 'Redo', accelerator: 'Shift+Command+Z', selector: 'redo:' },
9093
{ type: 'separator' },
@@ -136,13 +139,12 @@ export default class MenuBuilder {
136139
}
137140
]
138141
};
139-
const subMenuWindow: MenuItemConstructorOptions = {
142+
const subMenuWindow: DarwinMenuItemConstructorOptions = {
140143
label: 'Window',
141144
submenu: [
142145
{
143146
label: 'Minimize',
144147
accelerator: 'Command+M',
145-
// @ts-ignore
146148
selector: 'performMiniaturize:'
147149
},
148150
{ label: 'Close', accelerator: 'Command+W', selector: 'performClose:' },

0 commit comments

Comments
 (0)