{"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":"validation","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/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/lib/type_builders.ts#L3895-L3931","documentation":"When validating index arguments in #[spacetimedb::table(index(...))], the macro requires a Direct index column to carry #[unique]. A direct index maps each column value to at most one row, which is only sound for unique columns, so the combination without #[unique] is rejected at derive time.","triggerScenarios":"Declaring a direct index on a column that is not marked #[unique], e.g. a table with #[index(direct)] (or the direct index form naming that column) but no #[unique] attribute on the field.","commonSituations":"Adding 'direct' for fast point lookups without realizing it implies uniqueness; removing #[unique] during a refactor while keeping the direct index.","solutions":["Add #[unique] to the same column if values are guaranteed distinct.","If duplicate values must be allowed, use #[index(btree)] or #[index(hash)] instead — they index many rows per key.","Verify #[unique] sits on the column (field attribute), not on the table."],"exampleFix":"// before\n#[spacetimedb::table(index(direct = email))]\npub struct User { #[auto_inc] pub id: u64, pub email: String }\n\n// after\n#[spacetimedb::table(index(direct = email))]\npub struct User {\n    #[auto_inc] pub id: u64,\n    #[unique] pub email: String,   // direct index requires unique\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair every direct index with #[unique] on the same column by habit.","If duplicates are possible, choose btree or hash indexes instead of direct.","Review index attributes whenever a column's uniqueness changes."],"tags":["spacetimedb","proc-macro","index","unique-constraint","table","compile-time"],"backgroundTag":"index-constraint-mismatch","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}