A branded string type that represents a unique identifier for a record. The brand ensures type safety by preventing mixing of IDs between different record types.

type RecordId<R extends UnknownRecord> = string & {
  __type__: R
}

Example

// Define a Book record
interface Book extends BaseRecord<'book', RecordId<Book>> {
  title: string
  author: string
}

const bookId: RecordId<Book> = 'book:abc123' as RecordId<Book>
const authorId: RecordId<Author> = 'author:xyz789' as RecordId<Author>

// TypeScript prevents mixing different record ID types
// bookId = authorId // Type error!
Prev
RecordFromId
Next
RecordScope