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

  1. Construct the item with type: 'checkbox' if you need checkable state.
  2. 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

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


AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13). Data as JSON: /api/errors/84831246a96abb71. Report an issue: GitHub.