{"record":{"id":"6457d1c79a252de0","repo":"nwjs/nw.js","slug":"checked-property-is-only-available-for-checkbox","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/api/menuitem/menuitem.js","lineNumber":165,"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 this.handleGetter('checked');\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 v8_util.getHiddenValue(this, 'submenu');\n});\n\nMenuItem.prototype.__defineSetter__('submenu', function(val) {\n  if (v8_util.getConstructorName(val) != 'Menu')","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/menuitem/menuitem.js#L147-L183","documentation":"The `checked` setter throws a TypeError unless the item's type is 'checkbox'. The getter, by contrast, returns undefined for non-checkbox items. So reading is safe but writing is rejected. This matches the constructor rule that only checkbox items carry checkable state.","triggerScenarios":"Assigning `normalItem.checked = true` or `separatorItem.checked = false`. The item was created with type 'normal' (the default) and the developer tries to toggle it.","commonSituations":"Building toggle behavior on a normal item by mistake. Conditional code that sets `checked` without first checking the item type. Copying state between items of different types.","solutions":["Construct the item as type 'checkbox' if you need checkable state.","Guard the assignment: `if (item.type === 'checkbox') item.checked = val;`.","To convert, rebuild the item as a checkbox (type is immutable — see error 13)."],"exampleFix":"// before\nvar item = new nw.MenuItem({ label: 'Option' }); // type defaults to normal\nitem.checked = true; // throws\n\n// after\nvar item = new nw.MenuItem({ type: 'checkbox', label: 'Option', checked: true });","handlingStrategy":"validation","validationCode":"function setChecked(item, val) {\n  if (item.type !== 'checkbox')\n    throw new TypeError('checked only valid for checkbox items');\n  item.checked = val;\n}","typeGuard":"function isCheckboxItem(item) { return item.type === 'checkbox'; }","tryCatchPattern":"try { item.checked = val; }\ncatch (e) {\n  if (e instanceof TypeError && /checkbox/.test(e.message)) {\n    // rebuild as checkbox (type is immutable; see error 13)\n    throw new Error('Item is not a checkbox; rebuild it to use checked.');\n  } throw e;\n}","preventionTips":["Only set `checked` on items built with type 'checkbox'.","Guard assignments with an item.type check.","Model toggles with checkbox items from the start."],"tags":["nwjs","menuitem","checkbox","validation","state"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}