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
- Add the missing second (and further) arguments to the and helper call
- Replace a single-argument and with the value itself or an inline expression (e.g. {{if this.flag this.flag}})
- Guard dynamic argument spreads so at least two values are always passed
- 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
- Pass at least two arguments to and/{{and}} every time
- Replace single-argument and with the value directly or {{if}}
- Guard dynamic spreads ({{and ...list}}) to ensure minimum length
- Add template lint rules or unit tests covering helper call arity
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
- Compile Error: ${template.problem} @ ${template.span.start}.
- Compile Error: ${error.problem} @ ${error.span.start}..${err
- Compile Error: ${template.problem} @ ${template.span.start}.
- `eq` expects exactly two arguments, but received ${arguments
- `gt` expects exactly two arguments, but received ${arguments
AI-assisted analysis of emberjs/ember.js@26f97246a8 (2026-09-01).
Data as JSON: /api/errors/d277fed3237dc1f3.
Report an issue: GitHub.