nwjs/nw.js · error · TypeError
'checked' property is only available for checkbox
Error message
'checked' property is only available for checkbox
What it means
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.
Source
Thrown at src/api/menuitem/menuitem.js:165
MenuItem.prototype.__defineGetter__('modifiers', function() {
return this.handleGetter('modifiers');
});
MenuItem.prototype.__defineSetter__('modifiers', function(val) {
this.handleSetter('modifiers', 'SetModifiers', String, val);
});
MenuItem.prototype.__defineGetter__('checked', function() {
if (this.type != 'checkbox')
return undefined;
return this.handleGetter('checked');
});
MenuItem.prototype.__defineSetter__('checked', function(val) {
if (this.type != 'checkbox')
throw new TypeError("'checked' property is only available for checkbox");
this.handleSetter('checked', 'SetChecked', Boolean, val);
});
MenuItem.prototype.__defineGetter__('enabled', function() {
return this.handleGetter('enabled');
});
MenuItem.prototype.__defineSetter__('enabled', function(val) {
this.handleSetter('enabled', 'SetEnabled', Boolean, val);
});
MenuItem.prototype.__defineGetter__('submenu', function() {
return v8_util.getHiddenValue(this, 'submenu');
});
MenuItem.prototype.__defineSetter__('submenu', function(val) {
if (v8_util.getConstructorName(val) != 'Menu')View on GitHub (pinned to e15da848e9)
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).
Example fix
// before
var item = new nw.MenuItem({ label: 'Option' }); // type defaults to normal
item.checked = true; // throws
// after
var item = new nw.MenuItem({ type: 'checkbox', label: 'Option', checked: true }); Defensive patterns
Strategy: validation
Validate before calling
function setChecked(item, val) {
if (item.type !== 'checkbox')
throw new TypeError('checked only valid for checkbox items');
item.checked = val;
} Type guard
function isCheckboxItem(item) { return item.type === 'checkbox'; } Try / catch
try { item.checked = val; }
catch (e) {
if (e instanceof TypeError && /checkbox/.test(e.message)) {
// rebuild as checkbox (type is immutable; see error 13)
throw new Error('Item is not a checkbox; rebuild it to use checked.');
} throw e;
} Prevention
- Only set `checked` on items built with type 'checkbox'.
- Guard assignments with an item.type check.
- Model toggles with checkbox items from the start.
When it happens
Trigger: Assigning `normalItem.checked = true` or `separatorItem.checked = false`. The item was created with type 'normal' (the default) and the developer tries to toggle it.
Common situations: 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.
Related errors
- Invalid option.
- Invalid MenuItem type: {option.type}
- A normal MenuItem must have a label
- 'checked' property is only available for checkbox
- Invalid menu type: {option.type}
AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13).
Data as JSON: /api/errors/6457d1c79a252de0.
Report an issue: GitHub.