Types
Store Types
Types for schema-driven KV store definitions and type inference.
⌘I
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
CollabKit is currently in Beta. APIs and features may change.
Types for schema-driven KV store definitions and type inference.
import type { StoreFieldDefinition, StoreSchema, StoresConfig, InferDocument } from '@collab-kit/utils';
interface StoreFieldDefinition {
type: 'string' | 'number' | 'boolean';
required?: boolean;
default?: string | number | boolean;
}
type StoreSchema = Record<string, StoreFieldDefinition>;
type StoresConfig = Record<string, StoreSchema>;
type InferDocument<S extends StoreSchema> = {
[K in keyof S as S[K] extends { required: true } ? K : never]: FieldTypeMap[S[K]['type']];
} & {
[K in keyof S as S[K] extends { required: true } ? never : K]?: FieldTypeMap[S[K]['type']];
};
const schema = {
theme: { type: 'string' as const, required: true as const },
fontSize: { type: 'number' as const, required: true as const },
notifications: { type: 'boolean' as const },
};
// InferDocument<typeof schema> resolves to:
// { theme: string; fontSize: number; notifications?: boolean }