Download the PHP package frolaxhq/laravel-typescript without Composer
On this page you can find all versions of the php package frolaxhq/laravel-typescript. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download frolaxhq/laravel-typescript
More information about frolaxhq/laravel-typescript
Files in frolaxhq/laravel-typescript
Package laravel-typescript
Short Description Generate TypeScript interfaces from your Laravel Eloquent models
License MIT
Homepage https://github.com/frolaxhq/laravel-typescript
Informations about the package laravel-typescript
Generate TypeScript interfaces from your Eloquent models automatically. Keep your frontend types in sync with your database schema and model definitions.
📚 Read the Full Documentation
✨ Features
- Automatic Model Discovery — Automatically finds models in your codebase (PSR-4) without manual path config
- Automatic type generation — Scans your models and generates TypeScript interfaces/types
- Full type resolution — Precedence chain: overrides → docblocks → accessors → casts → DB types
- Import-aware overrides — Define external TypeScript symbols per field with automatic import dedup
- Relation support — Deep support for all Eloquent relations, counts, exists, and sums
- Enum support — Generate const objects, TypeScript enums, or union types
- Standalone Types — Define custom TypeScript interfaces in your config
- API Resources — Optional
{ data: T }response wrappers - Per-model files — One file per model with barrel export, or single bundled file
- Incremental builds — Intelligent caching for fast generation
- Formatter integration — Auto-format with Prettier or Biome
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
Publish the configuration:
Quick Start
Generate TypeScript definitions:
Output to stdout:
Generate for a specific model:
Output Example
Given this Eloquent model:
The generated TypeScript:
CLI Commands
typescript:generate
Generate TypeScript definitions from Eloquent models.
| Option | Description |
|---|---|
model |
Generate for a specific model only |
--output=PATH |
Output path (overrides config) |
--writer=TYPE |
Writer: interface, type, or json |
--enum-style=STYLE |
Enum style: const_object, ts_enum, union |
--global |
Wrap in declare namespace |
--plurals |
Pluralize type names (User → Users) |
--fillables |
Generate fillable-only types |
--no-relations |
Exclude relations |
--no-counts |
Exclude relation counts |
--timestamps-as-date |
Map timestamps to Date instead of string |
--optional-nullables |
Make nullable columns optional (name?: type) |
--connection=NAME |
Database connection to use |
--strict |
Bail on first model error |
--stdout |
Output to stdout only |
typescript:inspect
Inspect a model's metadata:
typescript:mappings
Show current type mappings:
Configuration
All options are documented in config/typescript.php. Key sections:
Discovery
Output
Writer
Relations
Custom Type Mappings
Naming Convention
Formatter
Incremental Builds
Extension API
Use the Typescript facade to extend the package:
Custom Type Mappers
Forced Type Overrides
Use the $interfaces property on your model:
String form and object form can be mixed in the same model.
Entries in $interfaces are emitted even when the field is not a database column,
accessor, or appended attribute. If the field already exists, the entry acts as a
forced type override.
When using import, generated files include import type statements automatically.
If multiple fields reference the same symbol/path pair, it is imported only once per output file.
Example generated import block:
Architecture
The package uses a pipeline architecture:
Each stage has a clear contract and can be replaced or extended:
| Module | Contract | Default |
|---|---|---|
| Discovery | ModelDiscoveryContract |
ModelDiscovery |
| Introspection | SchemaIntrospectorContract |
LaravelSchemaIntrospector |
| Metadata | ModelMetadataExtractorContract |
ModelMetadataExtractor |
| Type Resolution | TypeResolverContract |
TypeResolver |
| Relations | RelationResolverContract |
RelationResolver |
| Writing | WriterContract |
TypescriptWriter |
| Formatting | FormatterContract |
NullFormatter |
Type Resolution Precedence
Types are resolved using an 8-level precedence chain:
- Forced override —
$interfacesproperty on model - API resource type — When
api_resourcesmode is enabled - Enum cast —
AsEnumCollection,AsEnumArrayObject - Accessor return type — PHP return type from accessor method
- Cast type — Eloquent
$castsproperty - DB column type — Raw database schema type
- Custom user mapping — From
config('typescript.mappings.custom') - Fallback —
unknown
Testing
The test suite includes 135+ tests covering:
- Unit tests for all components (mappers, resolvers, writers, cache)
- Integration tests (schema introspection, metadata extraction)
- E2E pipeline tests (full generation flow)
- Artisan command tests
License
MIT
All versions of laravel-typescript with dependencies
spatie/laravel-package-tools Version ^1.16
composer/class-map-generator Version ^1.4
illuminate/contracts Version ^11.0|^12.0|^13.0