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

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

diephp/laravel-resources-typescript
===================================

Generate typescript interfaces from laravel resources

v0.1.5(1y ago)120MITPHPPHP ^8.0

Since Feb 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/diephp/laravel-resources-typescript)[ Packagist](https://packagist.org/packages/diephp/laravel-resources-typescript)[ RSS](/packages/diephp-laravel-resources-typescript/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Laravel Resources to TypeScript Interfaces
==========================================

[](#laravel-resources-to-typescript-interfaces)

A package to generate TypeScript interfaces from **STANDARD** Laravel Resource files, which are commonly used in API responses.

If you don’t want to sacrifice performance by installing large packages that do the same thing but require a specific file structure, DTOs, ValueObjects, and rewriting everything using new objects from scratch, or if you already have a project that uses standard Laravel Resources to format API responses, then this package is for you. I created it because Laravel Resources are more than sufficient for building REST API applications. I am testing this package in my own applications, and so far, it covers all the use cases I’ve encountered. If you have a scenario where it falls short, feel free to let me know.

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

[](#installation)

To install the package, use the following Composer command:

```
composer require diephp/laravel-resources-typescript
```

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

[](#configuration)

### Laravel 11+

[](#laravel-11)

If you are using **Laravel 11** or newer, you need to manually register the service provider. Add the following provider to your `bootstrap/providers.php` file:

```
\DiePHP\LaravelResourcesTypescript\Providers\LaravelResourcesTypescriptProvider::class,
```

### Setup config

[](#setup-config)

config/resources2typescript.php

*change `output_typescript_file`* for your real path

```
// Directory with laravel resources
'resources_dir' => 'app/Http/Resources',

// Final typescript file with interfaces
'output_typescript_file' => 'resources/ts/Resources.ts',

// Array of parces, you can remove or add yours parcels
'parsers' => [
    ArrayShapeParser::class, // parce ArrayShape signature
    PhpDocParser::class, // parce phpdoc signature
    ToArrayParser::class, // parce method toArray in resource
    FillableParser::class, // parcel model with protect $fillable = []
],

```

For older versions of Laravel, automatic package discovery will handle this for you.

Usage
-----

[](#usage)

Once the package is installed and configured, it will automatically generate TypeScript interfaces from your Laravel Resource files. These interfaces can then be utilized in your TypeScript-based frontend projects for better type safety and code consistency.

#### Run command for generate typescript interfaces

[](#run-command-for-generate-typescript-interfaces)

```
php artisan diephp:generate-typescript-interfaces
```

Examples
--------

[](#examples)

Assume you have a Laravel Resource like this:

### 1 standard resource without declaration

[](#1-standard-resource-without-declaration)

```
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ExampleResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
        ];
    }
}
```

The package will generate a corresponding TypeScript interface:

```
export interface ExampleResource {
    id: any;
    name: any;
}
```

This generated file can now be used in your frontend structure.

### 2 resource with ArrayShape

[](#2--resource-with-arrayshape)

```
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ExampleResource extends JsonResource
{
    #[ArrayShape(['id' => "int", 'name' => "string"])] public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
        ];
    }
}
```

The package will generate a corresponding TypeScript interface:

```
export interface ExampleResource {
    id: number;
    name: string;
}
```

This generated file can now be used in your frontend structure.

### 3 resource with PHPDOC

[](#3--resource-with-phpdoc)

```
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ExampleResource extends JsonResource
{
    /**
     * @return array{
     *     id: int,
     *     name: string,
     * }
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
        ];
    }
}
```

The package will generate a corresponding TypeScript interface:

```
export interface ExampleResource {
    id: number;
    name: string;
}
```

This generated file can now be used in your frontend structure.

### 4 resource simple toArray with types

[](#4--resource-simple-toarray-with-types)

```
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ExampleResource extends JsonResource
{

    public function toArray($request)
    {
        return [
            'id' => (int) $this->id,
            'name' => (string) $this->name,
        ];
    }
}
```

The package will generate a corresponding TypeScript interface:

```
export interface ExampleResource {
    id: number;
    name: string;
}
```

This generated file can now be used in your frontend structure.

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

[](#contributing)

If you would like to contribute, feel free to submit a pull request or file an issue on the [GitHub repository](https://github.com/diephp/laravel-resources-typescript).

License
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance43

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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

Every ~0 days

Total

2

Last Release

447d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/843845c3857f227042e7ae4ea3f5e255f8e14fc59d6a971b72bc0670996e7701?d=identicon)[diephp](/maintainers/diephp)

---

Top Contributors

[![AnatolyAstapov](https://avatars.githubusercontent.com/u/12308843?v=4)](https://github.com/AnatolyAstapov "AnatolyAstapov (7 commits)")

---

Tags

interfaceslaraveltypescriptresourcesgenerate

### Embed Badge

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

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

###  Alternatives

[okipa/laravel-table

Generate tables from Eloquent models.

56752.8k](/packages/okipa-laravel-table)[dirape/token

Unique Token Generator For Laravel

28277.4k2](/packages/dirape-token)[okipa/laravel-form-components

Ready-to-use and customizable form components.

198.0k1](/packages/okipa-laravel-form-components)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

188.5k](/packages/tarfin-labs-event-machine)[owowagency/laravel-resources

A package to develop projects faster.

1112.0k2](/packages/owowagency-laravel-resources)

PHPackages © 2026

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