clockworklabs/SpacetimeDB · error · TypeError

When providing a name, you must also provide the object.

Error message

When providing a name, you must also provide the object.

What it means

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.

Source

Thrown at crates/bindings-typescript/src/lib/type_builders.ts:3913

   * @returns A new {@link F64Builder} instance
   */
  f64: (): F64Builder => new F64Builder(),

  /**
   * Creates a new `Product` {@link AlgebraicType} to be used in table definitions. Product types in SpacetimeDB
   * are essentially the same as objects in JavaScript/TypeScript.
   * Properties of the object must also be {@link TypeBuilder}s.
   * Represented as an object with specific properties in TypeScript.
   *
   * @param name (optional) A display name for the product type. If omitted, an anonymous product type is created.
   * @param obj The object defining the properties of the type, whose property
   * values must be {@link TypeBuilder}s.
   * @returns A new {@link ProductBuilder} instance.
   */
  object: ((nameOrObj: any, maybeObj?: any) => {
    if (typeof nameOrObj === 'string') {
      if (!maybeObj) {
        throw new TypeError(
          'When providing a name, you must also provide the object.'
        );
      }
      return new ProductBuilder(maybeObj, nameOrObj);
    }
    return new ProductBuilder(nameOrObj, undefined);
  }) as {
    <Obj extends ElementsObj>(name: string, obj: Obj): ProductBuilder<Obj>;
    // TODO: Currently names are not optional
    // <Obj extends ElementsObj>(obj: Obj): ProductBuilder<Obj>;
  },

  /**
   * Creates a new `Row` {@link AlgebraicType} to be used in table definitions. Row types in SpacetimeDB
   * are similar to `Product` types, but are specifically used to define the schema of a table row.
   * Properties of the object must also be {@link TypeBuilder} or {@link ColumnBuilder}s.
   *
   * You can represent a `Row` as either a {@link RowObj} or an {@link RowBuilder} type when

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Pass the object: t.object('Player', { name: t.string, hp: t.u32 })
  2. Drop the name if anonymity is acceptable for the position (nested use)

Example fix

// before
const player = t.object('Player'); // -> TypeError

// after
const player = t.object('Player', { name: t.string, hp: t.u32 });
Defensive patterns

Strategy: validation

Validate before calling

function objectArgsValid(nameOrObj: unknown, maybeObj: unknown): boolean {
  return typeof nameOrObj !== 'string' || Boolean(maybeObj);
}
// objectArgsValid(nameOrObj, maybeObj) before calling t.object

Prevention

When it happens

Trigger: t.object('Player') - the name was given but the elements object was omitted.

Common situations: Partial refactors where the object literal is dropped; autocomplete filling only the first parameter; scaffolding code that conditionally builds the object but passes undefined.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/9609e7eee6085c49. Report an issue: GitHub.