createRecordType
Creates a new RecordType with the specified configuration.
This factory function creates a RecordType that can be used to create, validate, and manage records of a specific type within a store. The resulting RecordType can be extended with default properties using the withDefaultProperties method.
function createRecordType<R extends UnknownRecord>(
typeName: R["typeName"],
config: {
ephemeralKeys?: {
readonly [K in Exclude<keyof R, "id" | "typeName">]: boolean;
};
scope: RecordScope;
validator?: StoreValidator<R>;
},
): RecordType<R, keyof Omit<R, "id" | "typeName">>;Example
interface BookRecord extends BaseRecord<"book", RecordId<BookRecord>> {
title: string;
author: string;
inStock: boolean;
}
const Book = createRecordType<BookRecord>("book", {
scope: "document",
validator: bookValidator,
});Parameters
| Name | Description |
|---|---|
| The unique type name for this record type |
| Configuration object containing validator, scope, and ephemeral keys |
Returns
RecordType<R, keyof Omit<R, "id" | "typeName">>;A new RecordType instance for creating and managing records
Prev
createMigrationSequenceNext
devFreeze