Just launched the Electron app using TypeScript, and I'm trying to customize my custom menu. I followed an example in JS, but the line
menu = Menu.buildFromTemplate(template); unable to compile with error:
main.ts(109,35): error TS2345: Argument of type '({ label: string; submenu: ({ role: string; } | { type: string; })[]; } | { role: string; submenu...' is not assignable to parameter of type 'MenuItemConstructorOptions[]'.
Something is missing for me. Could not find type 'MenuItemConstructorOptions anywhere (but maybe I was looking for the wrong places). My complete code for main.ts is : import {app, BrowserWindow, screen, Menu} from' electronic '; import * as a path from' path ";
let win, menu;
function createWindow() {
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
win = new BrowserWindow({
x: 0,
y: 0,
width: size.width,
height: size.height
});
win.loadURL('file://' + __dirname + '/index.html');
win.webContents.openDevTools();
win.on('closed', () => {
win = null;
});
}
function createMenu() {
const template = [{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{ role: 'window', submenu: [{ role: 'minimize' }, { role: 'close' }] },
{
role: 'help',
submenu: [{
label: 'Learn More',
click() {
require('electron').shell.openExternal('https://electron.atom.io');
}
}]
}
];
menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
try {
app.on('ready', function() {
createWindow();
createMenu();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
} catch (e) {
throw e;
}