Skip to content

TypeScript SDK timestamps are mistyped or improperly serialized #3433

@douglance

Description

@douglance

For this table:

const message = table(
  { name: "Message", public: true },
  {
    sender: t.identity(),
    sent: t.timestamp(),
    text: t.string(),
  },
);

using this method:

ctx.db.Message.insert({
  sender: ctx.sender,
  sent: ctx.timestamp,
  text: text.trim(),
});

throws:

runtime error: js error Uncaught SyntaxError: Cannot convert [object Object] to a BigInt
        at writeI64 (spacetimedb_module:392:14)
        at serializeValue (spacetimedb_module:978:12)
        at serializeValue (spacetimedb_module:1070:52)
        at serializeValue (spacetimedb_module:943:18)
        at serializeValue (spacetimedb_module:1070:52)
        at serializeValue (spacetimedb_module:943:18)
        at insert (spacetimedb_module:3384:18)
        at <anonymous> (spacetimedb_module:3721:33)
        at __call_reducer__ (spacetimedb_module:3341:30)

But if we use:

ctx.db.Message.insert({
  sender: ctx.sender,
  sent: ctx.timestamp.__timestamp_micros_since_unix_epoch__,
  text: text.trim(),
});

It serializes properly.

But the type of sent in the inserted payload throws this type error:

Type 'bigint' is not assignable to type 'Timestamp'. (ts 2322)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions