{"record":{"id":"abfeafb65bc859e2","repo":"nwjs/nw.js","slug":"invalid-menuitem-type-option-type","errorCode":null,"errorMessage":"Invalid MenuItem type: {option.type}","messagePattern":"Invalid MenuItem type: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/menuitem/menuitem.js","lineNumber":33,"sourceCode":"// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES\n// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n//  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH\n// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n//  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nvar v8_util = process.binding('v8_util');\n\nfunction MenuItem(option) {\n  if (typeof option != 'object')\n    throw new TypeError('Invalid option.');\n\n  if (!option.hasOwnProperty('type'))\n    option.type = 'normal';\n\n  if (option.type != 'normal' &&\n      option.type != 'checkbox' &&\n      option.type != 'separator')\n    throw new TypeError('Invalid MenuItem type: ' + option.type);\n\n  if (option.type == 'normal' || option.type == 'checkbox') {\n    if (option.type == 'checkbox')\n      option.checked = Boolean(option.checked);\n\n    if (!option.hasOwnProperty('label'))\n      throw new TypeError('A normal MenuItem must have a label');\n    else\n      option.label = String(option.label);\n\n    if (option.hasOwnProperty('icon')) {\n      option.shadowIcon = String(option.icon);\n      option.icon = nw.getAbsolutePath(option.icon);\n    }\n\n    if (option.hasOwnProperty('iconIsTemplate'))\n      option.iconIsTemplate = Boolean(option.iconIsTemplate);\n    else","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/menuitem/menuitem.js#L15-L51","documentation":"After defaulting a missing `type` to 'normal', MenuItem's constructor allows only 'normal', 'checkbox', and 'separator'. Any other value throws a TypeError that interpolates the offending type. macOS-only types like 'selector' are NOT in this whitelist despite being used internally by createMacBuiltin.","triggerScenarios":"Calling new nw.MenuItem({ type: 'radio' }), { type: 'submenu' }, or { type: 'check' }. Passing a misspelled value like 'checlbox' or 'Normal'.","commonSituations":"Developers coming from Electron's MenuItem (which has 'radio' and 'submenu' roles/​types). Typos. Assuming case-insensitivity ('Normal' throws).","solutions":["Use one of the three allowed values: 'normal', 'checkbox', or 'separator'.","If you need a submenu, use type 'normal' (the default) and set the `submenu` property to a Menu.","For radio-like behavior, model it with 'checkbox' items and toggle siblings on click."],"exampleFix":"// before\nnew nw.MenuItem({ type: 'radio', label: 'Opt' }); // throws\n\n// after\nnew nw.MenuItem({ type: 'checkbox', label: 'Opt', checked: true });","handlingStrategy":"validation","validationCode":"var TYPES = ['normal', 'checkbox', 'separator'];\nfunction buildItem(opt) {\n  opt = opt || {};\n  if (opt.type && TYPES.indexOf(opt.type) === -1)\n    throw new Error('Invalid MenuItem type: ' + opt.type);\n  return new nw.MenuItem(opt);\n}","typeGuard":"function isItemType(t) {\n  return t === 'normal' || t === 'checkbox' || t === 'separator';\n}","tryCatchPattern":"try { return new nw.MenuItem(opt); }\ncatch (e) {\n  if (e instanceof TypeError && /Invalid MenuItem type/.test(e.message)) {\n    delete opt.type; // let it default to 'normal'\n    return new nw.MenuItem(opt);\n  } throw e;\n}","preventionTips":["Whitelist the type before constructing.","Leave type unset to get the 'normal' default.","Use 'checkbox' for radio-like toggles."],"tags":["nwjs","menuitem","constructor","validation"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}