A TypeScript type generator for PocketBase collections. This tool automatically generates TypeScript interfaces and types from your PocketBase schema.
- Generates TypeScript interfaces for all PocketBase collections
- Supports all PocketBase field types
- Generates union types for select fields
- Handles optional fields
- Supports file fields (single and multiple)
- Excludes system collections by default
- Generates a Collections interface for type-safe access
# Using bun bun add pocketbase-typegen # Using npm npm install pocketbase-typegen # Using yarn yarn add pocketbase-typegenimport { pbTypegenFromFile, pbTypegenToFile } from 'pocketbase-typegen'; // Generate types and get as string const types = await pbTypegenFromFile('./schema.json'); console.log(types); // Generate types and save to file await pbTypegenToFile('./schema.json', './types.ts');import { pbTypegen } from 'pocketbase-typegen'; const schema = [/* your PocketBase schema */]; const types = pbTypegen(schema);The generator creates TypeScript interfaces and types like this:
export type CategoryOptions = 'web' | 'mobile' | 'design'; export interface ProjectRecord { id: string; title: string; description?: string; category?: CategoryOptions; files?: string[]; created?: string; updated?: string; } export interface Collections { projects: ProjectRecord; }text,email,url,editor→stringnumber→numberbool→booleandate→stringselect→ Custom union typejson→anyfile(single) →stringfile(multiple) →string[]relation→stringpassword→never
This project uses Bun for development. Make sure you have Bun installed.
# Install dependencies bun install # Run tests bun test # Generate types from sample schema bun run generateMIT
Contributions are welcome! Please feel free to submit a Pull Request.