oi-lab/oi-laravel-ts
A Laravel package that automatically generates TypeScript interfaces from your Eloquent models, with relationship support, custom casts, DataObjects, PHPDoc types, watch mode, and namespace filters for customization.
use_database_schema (default true): model attributes are read from the table. Every column the model serializes is emitted — fillable or not — typed from its cast or, when uncast, from its column type, and marked nullable (col?: T | null) when the column is. Falls back to $fillable when disabled or when the database is unreachable at generation time.declaration_style (default 'interface'): 'type' emits export type IFoo = { ... }; instead of export interface IFoo { ... }. A type alias is assignable to Record<string, T> — what Inertia's useForm / useHttp require — where an interface never is. Extension models become intersections.data_discriminators: emit a DTO as a discriminated union. Given a discriminant property and a map value => DTO class (literal, or a callable resolved at generation time), the DTO comes out as I{X}Base, I{X}{Property}Map and I{X} = I{X}Base & ( | { key: 'a'; prop: IA } | ... ), so narrowing on the discriminant narrows the property. The Record<string, unknown> member that absorbed a [@param](https://github.com/param) A|B|array<string, mixed> union is gone.list<T>, non-empty-list<T>, non-empty-array<K, V>, iterable<T> and Collection<K, T> resolve like array<K, T> instead of falling back to unknown without warning.array<int, string|int>) no longer recurses forever.never.int/bool/timestamp/immutable_datetime/decimal:*/hashed/encrypted no longer come out as never; array/json/collection come out as unknown.$hidden, #[Hidden]) are left out of model interfaces — they never reach the JSON.unknown instead of falling back to its column (a json column read as string), and | null is no longer appended to unknown.MorphTo relations are typed unknown and HasOneThrough / HasManyThrough resolve to their related model, instead of never.Attribute accessors listed in $appends are typed from their [@return](https://github.com/return) Attribute<TGet, TSet> annotation, or else from the getter closure's return type, instead of unknown (rendered never).use_database_schema on, model interfaces gain their non-fillable columns and nullable columns become col?: T | null. Timestamps stay required. Set use_database_schema => false for the previous output.Full Changelog: https://github.com/oi-lab/oi-laravel-ts/compare/v1.0.0...v1.0.2
Full Changelog: https://github.com/oi-lab/oi-laravel-ts/compare/v1.0.0...v1.0.1
Initial release of OI Laravel TypeScript Generator - a comprehensive Laravel package that automatically generates TypeScript interfaces from Eloquent models.
_count fields for relationshipsBuilt with clean architecture principles and separation of concerns:
Eloquent: Facade for model analysis and schema generationModelDiscovery: Discovers all Eloquent models in the applicationTypeExtractor: Extracts type information from model propertiesRelationshipResolver: Detects and extracts relationship metadataCastTypeResolver: Resolves custom Laravel casts to TypeScript typesDataObjectAnalyzer: Analyzes PHP DataObject classesPhpToTypeScriptConverter: Converts PHP types to TypeScriptSchemaBuilder: Orchestrates complete schema buildingConvert: Main orchestrator coordinating TypeScript generationTypeScriptTypeConverter: Handles schema to TypeScript type conversionDataObjectProcessor: Processes PHP DataObjects and generates interfacesModelInterfaceGenerator: Generates TypeScript interfaces for modelsImportManager: Manages TypeScript import statementsJsonLdGenerator: Generates JSON-LD support interfacesphp artisan oi:gen-ts - Generate TypeScript interfacesphp artisan oi:gen-ts --watch - Watch mode for automatic regenerationoutput_path - Custom output path for generated TypeScriptwith_counts - Include relationship count fieldswith_json_ld - Enable JSON-LD supportsave_schema - Save intermediate schema.json for debuggingprops_with_types - Define specific types for propertiescustom_props - Add custom properties to modelsHow can I help you explore Laravel packages today?