PHPackages                             frolaxhq/laravel-typescript - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. frolaxhq/laravel-typescript

ActiveLibrary[Database &amp; ORM](/categories/database)

frolaxhq/laravel-typescript
===========================

Generate TypeScript interfaces from your Laravel Eloquent models

v0.0.5(1mo ago)053↓90.9%MITPHPPHP ^8.3CI passing

Since Feb 18Pushed 3w agoCompare

[ Source](https://github.com/frolaxhq/laravel-typescript)[ Packagist](https://packagist.org/packages/frolaxhq/laravel-typescript)[ Docs](https://github.com/frolaxhq/laravel-typescript)[ GitHub Sponsors](https://github.com/frolaxhq)[ RSS](/packages/frolaxhq-laravel-typescript/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (5)Dependencies (42)Versions (7)Used By (0)

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](https://frolaxhq.github.io/laravel-typescript)

[](#-read-the-full-documentation)

---

✨ Features
----------

[](#-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
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

Installation
------------

[](#installation)

```
composer require frolax/laravel-typescript --dev
```

Publish the configuration:

```
php artisan vendor:publish --tag=typescript-config
```

Quick Start
-----------

[](#quick-start)

Generate TypeScript definitions:

```
php artisan typescript:generate
```

Output to stdout:

```
php artisan typescript:generate --stdout
```

Generate for a specific model:

```
php artisan typescript:generate User
```

Output Example
--------------

[](#output-example)

Given this Eloquent model:

```
class User extends Model
{
    protected $fillable = ['name', 'email'];
    protected $hidden = ['password'];
    protected $casts = [
        'email_verified_at' => 'datetime',
        'role' => UserRole::class,
    ];

    public function posts(): HasMany
    {
        return $this->hasMany(Post::class);
    }
}
```

The generated TypeScript:

```
// This file is auto-generated by laravel-typescript.
// Do not edit this file manually.

export interface User {
  // Columns
  id: number;
  name: string;
  email: string;
  email_verified_at: string | null;
  role: UserRole;
  password: string;
  created_at: string | null;
  updated_at: string | null;
  // Relations
  posts: Post[];
  // Counts
  posts_count?: number;
}

export const UserRole = {
  Admin: 'admin',
  User: 'user',
} as const;
export type UserRole = typeof UserRole[keyof typeof UserRole];
```

CLI Commands
------------

[](#cli-commands)

### `typescript:generate`

[](#typescriptgenerate)

Generate TypeScript definitions from Eloquent models.

```
php artisan typescript:generate [model] [options]
```

OptionDescription`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`

[](#typescriptinspect)

Inspect a model's metadata:

```
php artisan typescript:inspect "App\Models\User"
php artisan typescript:inspect "App\Models\User" --json
```

### `typescript:mappings`

[](#typescriptmappings)

Show current type mappings:

```
php artisan typescript:mappings
```

Configuration
-------------

[](#configuration)

All options are documented in `config/typescript.php`. Key sections:

### Discovery

[](#discovery)

```
'discovery' => [
    'auto_discover' => true,         // Automatically find models in your codebase
    'paths' => [app_path('Models')], // Add extra paths if needed
    'excluded_models' => ['BaseModel'],
],
```

### Output

[](#output)

```
'output' => [
    'path' => resource_path('types/generated'),
    'per_model_files' => true,       // One file per model
    'barrel_export' => true,         // Generate index.ts
    'enum_directory' => 'enums',     // Subdirectory for enums
],
```

### Writer

[](#writer)

```
'writer' => [
    'default' => 'interface',        // 'interface', 'type', or 'json'
    'enum_style' => 'const_object',  // 'const_object', 'ts_enum', 'union'
    'global_namespace' => null,      // Wrap in declare namespace
    'fillable_types' => false,       // Generate UserFillable types
],
```

### Relations

[](#relations)

```
'relations' => [
    'enabled' => true,
    'optional' => false,             // Make all relations optional
    'counts' => ['enabled' => true, 'optional' => true],
    'exists' => ['enabled' => true, 'optional' => true],
],
```

### Custom Type Mappings

[](#custom-type-mappings)

```
'mappings' => [
    'custom' => [
        'point' => '{ lat: number; lng: number }',
        'money' => 'string',
    ],
    'timestamps_as_date' => false,
],
```

### Naming Convention

[](#naming-convention)

```
'case' => [
    'columns' => 'camel',    // 'snake', 'camel', 'pascal'
    'relations' => 'camel',
],
```

### Formatter

[](#formatter)

```
'formatter' => [
    'enabled' => true,
    'tool' => 'prettier',    // 'prettier' or 'biome'
],
```

### Incremental Builds

[](#incremental-builds)

```
'cache' => [
    'enabled' => true,       // Skip unchanged models
],
```

Extension API
-------------

[](#extension-api)

Use the `Typescript` facade to extend the package:

### Custom Type Mappers

[](#custom-type-mappers)

```
use Frolax\Typescript\Facades\Typescript;

Typescript::extend(function ($registry) {
    $registry->registerMapper(new class implements TypeMapperContract {
        public function supports(string $type): bool
        {
            return $type === 'point';
        }

        public function resolve(string $type): string
        {
            return '{ lat: number; lng: number }';
        }
    });
});
```

### Forced Type Overrides

[](#forced-type-overrides)

Use the `$interfaces` property on your model:

```
class User extends Model
{
    public array $interfaces = [
        'metadata' => 'Record',
        'settings' => 'UserSettings',
        'attachments' => [
            'type' => 'MessagePartAttachment[]',
            'import' => '@/types/ai',
        ],
        'avatar' => [
            'type' => 'ImageAsset',
            'nullable' => true,
            'import' => '@/types/media',
        ],
    ];
}
```

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:

```
import type { ImageAsset } from '@/types/media';
import type { MessagePartAttachment } from '@/types/ai';
```

Architecture
------------

[](#architecture)

The package uses a pipeline architecture:

```
Discovery → Introspection → Metadata → Type Resolution → Relation Resolution → Writing → Formatting

```

Each stage has a clear contract and can be replaced or extended:

ModuleContractDefaultDiscovery`ModelDiscoveryContract``ModelDiscovery`Introspection`SchemaIntrospectorContract``LaravelSchemaIntrospector`Metadata`ModelMetadataExtractorContract``ModelMetadataExtractor`Type Resolution`TypeResolverContract``TypeResolver`Relations`RelationResolverContract``RelationResolver`Writing`WriterContract``TypescriptWriter`Formatting`FormatterContract``NullFormatter`### Type Resolution Precedence

[](#type-resolution-precedence)

Types are resolved using an 8-level precedence chain:

1. **Forced override** — `$interfaces` property on model
2. **API resource type** — When `api_resources` mode is enabled
3. **Enum cast** — `AsEnumCollection`, `AsEnumArrayObject`
4. **Accessor return type** — PHP return type from accessor method
5. **Cast type** — Eloquent `$casts` property
6. **DB column type** — Raw database schema type
7. **Custom user mapping** — From `config('typescript.mappings.custom')`
8. **Fallback** — `unknown`

Testing
-------

[](#testing)

```
composer test
```

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
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance94

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

5

Last Release

33d ago

PHP version history (2 changes)v0.0.1PHP ^8.4

v0.0.4PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/05f9a72ab9f1685e2d1e829714d6c3470ea38acc3bdf3b6608ac5edb4997b835?d=identicon)[bishwajitcadhikary](/maintainers/bishwajitcadhikary)

---

Top Contributors

[![bishwajitcadhikary](https://avatars.githubusercontent.com/u/55208330?v=4)](https://github.com/bishwajitcadhikary "bishwajitcadhikary (35 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

interfaceslaraveleloquenttypescripttypescodegen

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/frolaxhq-laravel-typescript/health.svg)

```
[![Health](https://phpackages.com/badges/frolaxhq-laravel-typescript/health.svg)](https://phpackages.com/packages/frolaxhq-laravel-typescript)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.3k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M46](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M95](/packages/dedoc-scramble)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17558.6k](/packages/lacodix-laravel-model-filter)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k35](/packages/spatie-laravel-passkeys)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213389.8k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
