clockworklabs/SpacetimeDB · error · TypeError
When providing a name, you must also provide the variants ob
Error message
When providing a name, you must also provide the variants object or array.
What it means
t.enum accepts either (variantsObj) for an anonymous sum or (name, variantsObj) for a named one. If the first argument is a string and the second is missing or falsy, there are no variants to build, so it throws TypeError - a name alone does not define a sum type.
Source
Thrown at crates/bindings-typescript/src/lib/type_builders.ts:3741
/**
* Creates a full sum type, where each case can have a payload.
* Each value in the object must be a {@link TypeBuilder}.
*
* Example:
* ```ts
* t.enum("Result", { Ok: t.unit(), Err: t.string() });
* ```
*/
<Obj extends VariantsObj>(name: string, obj: Obj): SumBuilder<Obj>;
}
const enumImpl = ((nameOrObj: any, maybeObj?: any) => {
let obj: any = nameOrObj;
let name: string | undefined = undefined;
if (typeof nameOrObj === 'string') {
if (!maybeObj) {
throw new TypeError(
'When providing a name, you must also provide the variants object or array.'
);
}
obj = maybeObj;
name = nameOrObj;
}
// Simple sum (array form)
if (Array.isArray(obj)) {
const simpleVariantsObj: Record<string, UnitBuilder> = {};
for (const variant of obj) {
simpleVariantsObj[variant] = new UnitBuilder();
}
return new SimpleSumBuilderImpl(simpleVariantsObj, name);
}
// Regular sum (object form)
return new SumBuilder(obj, name);View on GitHub (pinned to 524b4487d9)
Solutions
- Pass the variants: t.enum('Status', ['Active', 'Banned']) or t.enum('Status', { Active: t.unit(), Banned: t.string() })
- Drop the name if anonymity is intended: t.enum({ ... }) or t.enum([...])
Example fix
// before
const status = t.enum('Status'); // -> TypeError
// after
const status = t.enum('Status', ['Active', 'Banned']); Defensive patterns
Strategy: validation
Validate before calling
function enumArgsValid(nameOrObj: unknown, maybeObj: unknown): boolean {
return typeof nameOrObj !== 'string' || Boolean(maybeObj);
}
// enumArgsValid(nameOrObj, maybeObj) before calling t.enum Prevention
- Always supply the variants object or array when naming an enum
- Let the overload signatures guide you: name implies a second argument
- Run schema construction in a startup smoke test so arity mistakes fail fast
When it happens
Trigger: t.enum('Status') - the name was given but the variants object or array was omitted.
Common situations: Partial refactors where the variants object is deleted or commented out; IDE autocomplete inserting only the first argument; merging schema code and losing the second argument.
Related errors
- When providing a name, you must also provide the object.
- Missing type name for ${typeBuilder.constructor.name ?? 'Typ
- cannot serialize refs without a typespace
- cannot deserialize refs without a typespace
- could not serialize result: object had neither a `ok` nor an
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/ed90ef8bb40929d8.
Report an issue: GitHub.