PHPackages                             jdiassdev/laravel-types-gen - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jdiassdev/laravel-types-gen

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jdiassdev/laravel-types-gen
===========================

Generate TypeScript types from Laravel FormRequests and API Resources.

v1.0.0(2mo ago)13MITPHPPHP ^8.2CI passing

Since May 13Pushed 1mo agoCompare

[ Source](https://github.com/jdiassdev/laravel-types-gen)[ Packagist](https://packagist.org/packages/jdiassdev/laravel-types-gen)[ Docs](https://github.com/jdiassdev/laravel-types-gen)[ RSS](/packages/jdiassdev-laravel-types-gen/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Laravel TypesGen
================

[](#laravel-typesgen)

[![Tests](https://github.com/jdiassdev/laravel-types-gen/actions/workflows/tests.yml/badge.svg)](https://github.com/jdiassdev/laravel-types-gen/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/f3c62c80a6775d0e20152e64e54bb64872348bd16301499d41e5be031a3c8e86/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a64696173736465762f6c61726176656c2d74797065732d67656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdiassdev/laravel-types-gen)[![Total Downloads](https://camo.githubusercontent.com/cb20a0eee5a911f65920f202193bcb115410180a70953ef00c184e76aedfea0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a64696173736465762f6c61726176656c2d74797065732d67656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdiassdev/laravel-types-gen)[![PHP Version](https://camo.githubusercontent.com/cbc1c669e9bcb65be0f789d27a5db21a5669571fab5bf6c583eb4ba799d924a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a64696173736465762f6c61726176656c2d74797065732d67656e3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdiassdev/laravel-types-gen)[![License](https://camo.githubusercontent.com/d9ce1a72ddfc79effb808e4003db8c13553c560ee5325a18e5348bde9c3736b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a64696173736465762f6c61726176656c2d74797065732d67656e3f7374796c653d666c61742d737175617265)](LICENSE)

Generate TypeScript interfaces automatically from your Laravel **FormRequests** and **API Resources**. Keep your backend and frontend contracts in sync without any manual duplication.

```
php artisan ts:generate
```

```
// resources/types/api-request.ts — auto-generated

export interface StoreUserRequest {
  name: string;
  email: string;
  age: number | null;
  bio?: string;
}
```

---

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

---

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

[](#installation)

Install via Composer:

```
composer require jdiassdev/laravel-types-gen
```

The service provider is registered automatically via Laravel's package discovery. No additional setup required.

---

Usage
-----

[](#usage)

Run the artisan command from your project root:

```
php artisan ts:generate
```

Two files are generated inside `resources/types/`:

FileSource`api-request.ts``app/Http/Requests/**/*Request.php``api-resource.ts``app/Http/Resources/**/*Resource.php`---

How it works
------------

[](#how-it-works)

The package performs **static analysis** — it reads your PHP files directly without instantiating any class or booting the framework. This means it is safe to run at any point, including CI pipelines.

---

FormRequests
------------

[](#formrequests)

Both rule formats are supported.

**String style**

```
public function rules(): array
{
    return [
        'name'  => 'required|string',
        'email' => 'required|email',
        'age'   => 'required|integer|nullable',
        'bio'   => 'string',
    ];
}
```

**Array style**

```
public function rules(): array
{
    return [
        'name'  => ['required', 'string'],
        'tags'  => ['required', 'array'],
    ];
}
```

Generated output:

```
export interface StoreUserRequest {
  name: string;
  email: string;
  age: number | null;
  bio?: string;   // no `required` → optional
  tags: any[];
}
```

> Fields that do not have the `required` rule are emitted as optional (`field?: type`).

---

Nested fields
-------------

[](#nested-fields)

Dot-notation fields are converted into nested TypeScript objects and arrays.

```
public function rules(): array
{
    return [
        'address.city'   => 'required|string',
        'address.street' => 'string',
        'items.*.name'   => 'required|string',
        'items.*.qty'    => 'required|integer',
    ];
}
```

```
export interface StoreOrderRequest {
  address: {
    city: string;
    street?: string;
  };
  items: {
    name: string;
    qty: number;
  }[];
}
```

---

API Resources
-------------

[](#api-resources)

The package reads the return array of `toArray()` and extracts the field names. Since values depend on runtime data, all resource fields default to `any`.

```
public function toArray(Request $request): array
{
    return [
        'id'         => $this->id,
        'name'       => $this->name,
        'email'      => $this->email,
        'created_at' => $this->created_at,
    ];
}
```

```
export interface UserResource {
  id: any;
  name: any;
  email: any;
  created_at: any;
}
```

---

Type mapping
------------

[](#type-mapping)

Laravel ruleTypeScript type`string`, `email`, `url`, `date`, `uuid`, `ulid`, `ip`, `timezone`, `password``string``integer`, `numeric`, `decimal`, `float`, `double``number``boolean`, `accepted`, `declined``boolean``array``any[]``file`, `image``File``json``any``object``Record``nullable` modifier`type | null`field without `required``field?: type`---

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

[](#configuration)

The output path can be customized. Publish the config file:

```
php artisan vendor:publish --tag=laravel-types-gen-config
```

```
// config/laravel-types-gen.php

return [
    /*
    |--------------------------------------------------------------------------
    | Output Path
    |--------------------------------------------------------------------------
    |
    | The directory where the generated TypeScript files will be written.
    | Both api-request.ts and api-resource.ts are placed inside this path.
    |
    */
    'output_path' => resource_path('types'),
];
```

---

Testing
-------

[](#testing)

```
composer test
```

---

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for information on recent changes.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability, please review our [security policy](.github/SECURITY.md) and report it responsibly.

Credits
-------

[](#credits)

- [João Dias](https://github.com/jdiassdev)
- [All Contributors](https://github.com/jdiassdev/laravel-types-gen/contributors)

License
-------

[](#license)

The MIT License. Please see [LICENSE](LICENSE) for more information.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance87

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

73d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/249618524?v=4)[João Victor Dias](/maintainers/jdiassdev)[@jdiassdev](https://github.com/jdiassdev)

---

Top Contributors

[![jdiassdev](https://avatars.githubusercontent.com/u/249618524?v=4)](https://github.com/jdiassdev "jdiassdev (6 commits)")

---

Tags

interfaceslaravel-packagephp-librarytypescriptlaravelgeneratortypescripttypesformrequestapi resource

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jdiassdev-laravel-types-gen/health.svg)

```
[![Health](https://phpackages.com/badges/jdiassdev-laravel-types-gen/health.svg)](https://phpackages.com/packages/jdiassdev-laravel-types-gen)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[illuminate/queue

The Illuminate Queue package.

20432.6M1.7k](/packages/illuminate-queue)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React/Svelte) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

4925.3k](/packages/erag-laravel-lang-sync-inertia)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[flarum/core

Delightfully simple forum software.

211.4M2.4k](/packages/flarum-core)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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