BaseRecord

See source code
Table of contents

The base record interface that all records in the store must extend. This interface provides the fundamental structure required for all records: a unique ID and a type name. The type parameters ensure type safety and prevent mixing of different record types.

interface BaseRecord<
  TypeName extends string,
  Id extends RecordId<UnknownRecord>,
> {}

Example

// Define a Book record that extends BaseRecord
interface Book extends BaseRecord<"book", RecordId<Book>> {
  title: string;
  author: string;
  publishedYear: number;
}

// Define an Author record
interface Author extends BaseRecord<"author", RecordId<Author>> {
  name: string;
  birthYear: number;
}

// Usage with RecordType
const Book = createRecordType<Book>("book", { scope: "document" });
const book = Book.create({
  title: "1984",
  author: "George Orwell",
  publishedYear: 1949,
});
// Results in: { id: 'book:abc123', typeName: 'book', title: '1984', ... }

Properties

id

readonly
readonly id: Id;

typeName

readonly
readonly typeName: TypeName;

Prev
Signal
Next
CollectionDiff