{"record":{"id":"9609e7eee6085c49","repo":"clockworklabs/SpacetimeDB","slug":"when-providing-a-name-you-must-also-provide-the-o","errorCode":null,"errorMessage":"When providing a name, you must also provide the object.","messagePattern":"When providing a name, you must also provide the object\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/lib/type_builders.ts","lineNumber":3913,"sourceCode":"   * @returns A new {@link F64Builder} instance\n   */\n  f64: (): F64Builder => new F64Builder(),\n\n  /**\n   * Creates a new `Product` {@link AlgebraicType} to be used in table definitions. Product types in SpacetimeDB\n   * are essentially the same as objects in JavaScript/TypeScript.\n   * Properties of the object must also be {@link TypeBuilder}s.\n   * Represented as an object with specific properties in TypeScript.\n   *\n   * @param name (optional) A display name for the product type. If omitted, an anonymous product type is created.\n   * @param obj The object defining the properties of the type, whose property\n   * values must be {@link TypeBuilder}s.\n   * @returns A new {@link ProductBuilder} instance.\n   */\n  object: ((nameOrObj: any, maybeObj?: any) => {\n    if (typeof nameOrObj === 'string') {\n      if (!maybeObj) {\n        throw new TypeError(\n          'When providing a name, you must also provide the object.'\n        );\n      }\n      return new ProductBuilder(maybeObj, nameOrObj);\n    }\n    return new ProductBuilder(nameOrObj, undefined);\n  }) as {\n    <Obj extends ElementsObj>(name: string, obj: Obj): ProductBuilder<Obj>;\n    // TODO: Currently names are not optional\n    // <Obj extends ElementsObj>(obj: Obj): ProductBuilder<Obj>;\n  },\n\n  /**\n   * Creates a new `Row` {@link AlgebraicType} to be used in table definitions. Row types in SpacetimeDB\n   * are similar to `Product` types, but are specifically used to define the schema of a table row.\n   * Properties of the object must also be {@link TypeBuilder} or {@link ColumnBuilder}s.\n   *\n   * You can represent a `Row` as either a {@link RowObj} or an {@link RowBuilder} type when","sourceCodeStart":3895,"sourceCodeEnd":3931,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-typescript/src/lib/type_builders.ts#L3895-L3931","documentation":"t.object accepts either (obj) for an anonymous product or (name, obj) for a named one (the overload list currently documents the named form). If the first argument is a string and the second is missing or falsy, there are no elements to build, so it throws TypeError.","triggerScenarios":"t.object('Player') - the name was given but the elements object was omitted.","commonSituations":"Partial refactors where the object literal is dropped; autocomplete filling only the first parameter; scaffolding code that conditionally builds the object but passes undefined.","solutions":["Pass the object: t.object('Player', { name: t.string, hp: t.u32 })","Drop the name if anonymity is acceptable for the position (nested use)"],"exampleFix":"// before\nconst player = t.object('Player'); // -> TypeError\n\n// after\nconst player = t.object('Player', { name: t.string, hp: t.u32 });","handlingStrategy":"validation","validationCode":"function objectArgsValid(nameOrObj: unknown, maybeObj: unknown): boolean {\n  return typeof nameOrObj !== 'string' || Boolean(maybeObj);\n}\n// objectArgsValid(nameOrObj, maybeObj) before calling t.object","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply the elements object when naming a product type","Watch for refactors that delete the object literal but keep the name","Exercise type-builder declarations in a unit test at module load"],"tags":["type-builder","product-type","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"}