{"record":{"id":"84831246a96abb71","repo":"nwjs/nw.js","slug":"checked-property-is-only-available-for-checkbox-848312","errorCode":null,"errorMessage":"'checked' property is only available for checkbox","messagePattern":"'checked' property is only available for checkbox","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_menuitem.js","lineNumber":183,"sourceCode":"\nMenuItem.prototype.__defineGetter__('modifiers', function() {\n  return this.handleGetter('modifiers');\n});\n\nMenuItem.prototype.__defineSetter__('modifiers', function(val) {\n  this.handleSetter('modifiers', 'SetModifiers', String, val);\n});\n\nMenuItem.prototype.__defineGetter__('checked', function() {\n  if (this.type != 'checkbox')\n    return undefined;\n\n  return nw.Obj.callObjectMethodSync(this.id, 'MenuItem', 'GetChecked', []);\n});\n\nMenuItem.prototype.__defineSetter__('checked', function(val) {\n  if (this.type != 'checkbox')\n    throw new TypeError(\"'checked' property is only available for checkbox\");\n\n  this.handleSetter('checked', 'SetChecked', Boolean, val);\n});\n\nMenuItem.prototype.__defineGetter__('enabled', function() {\n  return this.handleGetter('enabled');\n});\n\nMenuItem.prototype.__defineSetter__('enabled', function(val) {\n  this.handleSetter('enabled', 'SetEnabled', Boolean, val);\n});\n\nMenuItem.prototype.__defineGetter__('submenu', function() {\n  return privates(this).submenu;\n});\n\nMenuItem.prototype.__defineSetter__('submenu', function(val) {\n  privates(this).submenu = val;","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_menuitem.js#L165-L201","documentation":"Thrown by the MenuItem 'checked' setter when the item's type is not 'checkbox'. Only checkbox items have a checkable state; setting .checked on a normal or separator item is meaningless and is rejected.","triggerScenarios":"Running `normalItem.checked = true` where the item was constructed with type 'normal' or 'separator'.","commonSituations":"Toggling a stored MenuItem reference that turned out to be a normal item; reusing the same handler for a mixed list of items.","solutions":["Construct the item with type: 'checkbox' if you need checkable state.","Guard before setting: `if (item.type === 'checkbox') item.checked = val;`."],"exampleFix":"// before\nconst item = new nw.MenuItem({ label: 'Opt' });\nitem.checked = true;\n// after\nconst item = new nw.MenuItem({ type: 'checkbox', label: 'Opt', checked: true });","handlingStrategy":"type-guard","validationCode":"if (item.type !== 'checkbox' && val !== undefined) throw new TypeError('checked only for checkbox items');","typeGuard":"function isCheckable(item) { return item && item.type === 'checkbox'; }","tryCatchPattern":"try { item.checked = val; } catch (e) { if (/checkbox/.test(e.message)) console.warn('item not checkable'); else throw e; }","preventionTips":["Check item.type === 'checkbox' before setting checked.","Construct checkbox items up front if state is needed."],"tags":["menuitem","setter","type-check","checkbox","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}