nwjs/nw.js · error · TypeError
'checked' property is only available for checkbox
Error message
'checked' property is only available for checkbox
What it means
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.
Source
Thrown at src/resources/api_nw_menuitem.js:183
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 nw.Obj.callObjectMethodSync(this.id, 'MenuItem', 'GetChecked', []);
});
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 privates(this).submenu;
});
MenuItem.prototype.__defineSetter__('submenu', function(val) {
privates(this).submenu = val;View on GitHub (pinned to e15da848e9)
Solutions
- Construct the item with type: 'checkbox' if you need checkable state.
- Guard before setting: `if (item.type === 'checkbox') item.checked = val;`.
Example fix
// before
const item = new nw.MenuItem({ label: 'Opt' });
item.checked = true;
// after
const item = new nw.MenuItem({ type: 'checkbox', label: 'Opt', checked: true }); Defensive patterns
Strategy: type-guard
Validate before calling
if (item.type !== 'checkbox' && val !== undefined) throw new TypeError('checked only for checkbox items'); Type guard
function isCheckable(item) { return item && item.type === 'checkbox'; } Try / catch
try { item.checked = val; } catch (e) { if (/checkbox/.test(e.message)) console.warn('item not checkable'); else throw e; } Prevention
- Check item.type === 'checkbox' before setting checked.
- Construct checkbox items up front if state is needed.
When it happens
Trigger: Running `normalItem.checked = true` where the item was constructed with type 'normal' or 'separator'.
Common situations: Toggling a stored MenuItem reference that turned out to be a normal item; reusing the same handler for a mixed list of items.
Related errors
- 'checked' property is only available for checkbox
- 'menu' property requries a valid Menu
- Invalid option.
- 'click' must be a valid Function
- 'type' is immutable at runtime
AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13).
Data as JSON: /api/errors/84831246a96abb71.
Report an issue: GitHub.