emberjs/ember.js · warning · Error

`and` expects at least two arguments, but received ${positio

Error message

`and` expects at least two arguments, but received ${positional.length}.

What it means

The {{and}} helper computes the logical AND of its positional arguments and requires at least two arguments to be meaningful. In DEBUG builds, invoking it with 0 or 1 positional args throws this error at computation time. Production builds skip the throw and just return the single/absent value.

Source

Thrown at packages/@glimmer/runtime/lib/helpers/and.ts:10

import { DEBUG } from '@glimmer/env';
import type { CapturedArguments } from '@glimmer/interfaces';
import { toBool } from '@glimmer/global-context';
import { createComputeRef, valueForRef } from '@glimmer/reference/lib/reference';

import { internalHelper } from './internal-helper';

export const and = internalHelper(({ positional }: CapturedArguments) => {
  if (DEBUG && positional.length < 2) {
    throw new Error(`\`and\` expects at least two arguments, but received ${positional.length}.`);
  }

  return createComputeRef(
    () => {
      let last: unknown;
      for (let i = 0; i < positional.length; i++) {
        let arg = positional[i];
        last = arg ? valueForRef(arg) : arg;
        if (!toBool(last)) return last;
      }
      return last;
    },
    null,
    'and'
  );
});

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Add the missing second (and further) arguments to the and helper call
  2. Replace a single-argument and with the value itself or an inline expression (e.g. {{if this.flag this.flag}})
  3. Guard dynamic argument spreads so at least two values are always passed
  4. Use && inside a helper/computed property instead of and for single-value truthiness

Example fix

// before
{{and this.isAdmin}}
// after
{{and this.isAdmin this.isActive}}
Defensive patterns

Strategy: validation

Validate before calling

function safeAnd(...values: unknown[]): unknown {
  if (values.length < 2) throw new Error('`and` requires at least two arguments');
  return values.every(Boolean);
}

Type guard

function hasMinArithmeticArgs(args: { positional: unknown[] }): args is { positional: [unknown, unknown, ...unknown[]] } {
  return args.positional.length >= 2;
}

Try / catch

try {
  result = invokeHelper('and', positional);
} catch (e) {
  if (String(e?.message).startsWith('`and` expects at least two arguments')) {
    result = Boolean(positional[0]); // degenerate fallback for single-arg case
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling the and helper with fewer than two positional arguments, e.g. {{and this.flag}}, {{and}}, or programmatic invocation of the helper with a positional array of length < 2 (DEBUG only).

Common situations: Template refactor that removed one of the arguments; dynamic argument lists (e.g. {{and ...conditions}}) that end up empty or single-element; misunderstanding that and accepts a single truthiness check like JavaScript's &&.

Related errors


AI-assisted analysis of emberjs/ember.js@26f97246a8 (2026-09-01). Data as JSON: /api/errors/d277fed3237dc1f3. Report an issue: GitHub.