{"record":{"id":"ed90ef8bb40929d8","repo":"clockworklabs/SpacetimeDB","slug":"when-providing-a-name-you-must-also-provide-the-v","errorCode":null,"errorMessage":"When providing a name, you must also provide the variants object or array.","messagePattern":"When providing a name, you must also provide the variants object or array\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/lib/type_builders.ts","lineNumber":3741,"sourceCode":"  /**\n   * Creates a full sum type, where each case can have a payload.\n   * Each value in the object must be a {@link TypeBuilder}.\n   *\n   * Example:\n   * ```ts\n   * t.enum(\"Result\", { Ok: t.unit(), Err: t.string() });\n   * ```\n   */\n  <Obj extends VariantsObj>(name: string, obj: Obj): SumBuilder<Obj>;\n}\n\nconst enumImpl = ((nameOrObj: any, maybeObj?: any) => {\n  let obj: any = nameOrObj;\n  let name: string | undefined = undefined;\n\n  if (typeof nameOrObj === 'string') {\n    if (!maybeObj) {\n      throw new TypeError(\n        'When providing a name, you must also provide the variants object or array.'\n      );\n    }\n    obj = maybeObj;\n    name = nameOrObj;\n  }\n\n  // Simple sum (array form)\n  if (Array.isArray(obj)) {\n    const simpleVariantsObj: Record<string, UnitBuilder> = {};\n    for (const variant of obj) {\n      simpleVariantsObj[variant] = new UnitBuilder();\n    }\n    return new SimpleSumBuilderImpl(simpleVariantsObj, name);\n  }\n\n  // Regular sum (object form)\n  return new SumBuilder(obj, name);","sourceCodeStart":3723,"sourceCodeEnd":3759,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-typescript/src/lib/type_builders.ts#L3723-L3759","documentation":"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.","triggerScenarios":"t.enum('Status') - the name was given but the variants object or array was omitted.","commonSituations":"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.","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([...])"],"exampleFix":"// before\nconst status = t.enum('Status'); // -> TypeError\n\n// after\nconst status = t.enum('Status', ['Active', 'Banned']);","handlingStrategy":"validation","validationCode":"function enumArgsValid(nameOrObj: unknown, maybeObj: unknown): boolean {\n  return typeof nameOrObj !== 'string' || Boolean(maybeObj);\n}\n// enumArgsValid(nameOrObj, maybeObj) before calling t.enum","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["type-builder","enum","spacetimedb","typescript","argument-validation"],"backgroundTag":"builder-missing-argument","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}