PHPackages                             diagonal/laravel-ts-enum-generator - 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. diagonal/laravel-ts-enum-generator

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

diagonal/laravel-ts-enum-generator
==================================

Generate runtime-usable TypeScript objects and enums from PHP enums with utils

0.3.0(1mo ago)43.7k↑29.2%1MITPHPPHP ^8.4CI passing

Since Jun 28Pushed 2mo agoCompare

[ Source](https://github.com/Diagonal-HQ/ts-enum-generator)[ Packagist](https://packagist.org/packages/diagonal/laravel-ts-enum-generator)[ Docs](https://github.com/diagonal/ts-enum-generator)[ GitHub Sponsors](https://github.com/Diagonal-HQ)[ RSS](/packages/diagonal-laravel-ts-enum-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (14)Versions (14)Used By (0)

Generate TypeScript definitions from PHP enums
==============================================

[](#generate-typescript-definitions-from-php-enums)

[![Latest Version on Packagist](https://camo.githubusercontent.com/132b981288262b07cdd245f30544129b0a232eec3930aee2d07d28a4d6c5effa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f446961676f6e616c2d48512f74732d656e756d2d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/diagonal/ts-enum-generator)[![Tests](https://camo.githubusercontent.com/0fb0910802a9c2dd33ef48558de502dc0a32d527ffcef556a0e56f1da02cba40/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f446961676f6e616c2d48512f74732d656e756d2d67656e657261746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/diagonal/ts-enum-generator/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/79d30b4806d2dabe8726418923824f3b5bfdb7d4d71e74235c88966b20c1b620/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f446961676f6e616c2d48512f74732d656e756d2d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/diagonal/ts-enum-generator)

This package can generate TypeScript definitions from your PHP enums. The generated TypeScript includes type definitions, runtime objects, and utility functions to make working with enums in your frontend applications a breeze.

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

[](#installation)

You can install the package via composer:

```
composer require diagonal/ts-enum-generator
```

You can publish the config file with:

```
php artisan vendor:publish --tag="ts-enum-generator-config"
```

This is the contents of the published config file:

```
return [
    'default_source_dir' => 'app/Enums',
    'default_destination_dir' => 'resources/ts/enums',

    'output' => [
        'use_namespaces' => true,
        'single_file' => true,
        'output_filename' => 'enums.ts',
        'namespace_separator' => '.',
        'include_comments' => true,
        'generate_runtime_objects' => true,
        'generate_per_type_utils' => true,
        'generate_generic_utils' => true,
        'types_only' => false,
    ],

    'namespace' => [
        'root_namespace' => null,
        'strip_namespace_prefix' => null,
        'namespace_suffix' => 'Enums',
    ],
];
```

Usage
-----

[](#usage)

Create PHP enums in your Laravel application:

```
