---
name: type-bridge-enum-generation-31cd719d70a0
description: Generates TypeScript/JavaScript enums from PHP backed enums using the type-bridge:enums Artisan command. Use when user says "generate TS enums", "sync enums to frontend", "type-bridge enums", or needs PHP enum values available in JavaScript/TypeScript.
---

# Laravel Type Bridge - Enum Generation

## When to use this skill
Use this skill when you need to:
- Generate frontend enum files from PHP enums
- Set up enum synchronization between backend and frontend
- Use the opt-in attribute for specific enums
- Run CI drift detection

## Overview

This package (`gaiatools/laravel-type-bridge`) generates TypeScript/JavaScript enums from PHP backed enums. Check the actual configuration in `config/type-bridge.php` for paths and output settings.

## Available Commands

```bash
# Generate enums using default format from config
php artisan type-bridge:enums

# Generate enums as JavaScript
php artisan type-bridge:enums --format=js

# Generate enums as TypeScript
php artisan type-bridge:enums --format=ts

# Check mode - validate enums without writing (CI drift detection)
php artisan type-bridge:enums --check

# Dirty mode - generate only new/changed enums
php artisan type-bridge:enums --dirty
```

## Opt-in Enum Generation

Use the `#[GenerateEnum]` attribute to explicitly mark enums for generation:

```php
<?php

namespace App\Enums;

use GaiaTools\TypeBridge\Attributes\GenerateEnum;

#[GenerateEnum]
enum ThemeVisibility: string
{
    case Private = 'private';
    case Unlisted = 'unlisted';
    case Public = 'public';
}
```

## GenerateEnum Attribute Options

```php
use GaiaTools\TypeBridge\Attributes\GenerateEnum;

// Basic usage - generate the enum
#[GenerateEnum]
enum Status: string
{
    case Active = 'active';
    case Inactive = 'inactive';
}

// Include PHPDoc comments in generated output
#[GenerateEnum(requiresComments: true)]
enum Status: string { ... }

// Generate with custom output format
#[GenerateEnum(outputFormat: 'js')]
enum Status: string { ... }

// Include enum groups (public static methods returning arrays)
#[GenerateEnum(includeMethods: ['staffRoles', 'memberRoles'])]
enum UserRole: string { ... }
```

## Enum Groups

Enum groups export curated subsets alongside the base enum. Define public static methods that return arrays:

```php
<?php

namespace App\Enums;

use GaiaTools\TypeBridge\Attributes\GenerateEnum;

#[GenerateEnum(includeMethods: ['staffRoles', 'memberRoles'])]
enum UserRole: string
{
    case Admin = 'admin';
    case Manager = 'manager';
    case Support = 'support';
    case Member = 'member';
    case Guest = 'guest';

    /** @return array<int, self> */
    public static function staffRoles(): array
    {
        return [self::Admin, self::Manager, self::Support];
    }

    /** @return array<int, string> */
    public static function memberRoles(): array
    {
        return [self::Member->value, self::Guest->value];
    }
}
```

Generated TypeScript output:

```typescript
export const UserRole = {
    Admin: 'admin',
    Manager: 'manager',
    Support: 'support',
    Member: 'member',
    Guest: 'guest',
} as const;

export type UserRole = typeof UserRole[keyof typeof UserRole];

export const StaffRoles = {
    Admin: UserRole.Admin,
    Manager: UserRole.Manager,
    Support: UserRole.Support,
} as const;

export const MemberRoles = [
    UserRole.Member,
    UserRole.Guest,
] as const;
```

## CI Integration

Use `--check` mode in CI to detect drift between PHP enums and generated frontend files:

```bash
php artisan type-bridge:enums --check
# Exit code 0 if in sync, 1 if differences found
```


---
Source attribution: GaiaTools
Original project: https://github.com/GaiaTools/laravel-type-bridge/blob/2c5009cd927402f306463278f3224ea17c533f8c/resources/boost/skills/type-bridge-enum-generation/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2025 Gaia Tools

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: GaiaTools
Original project: https://github.com/GaiaTools/laravel-type-bridge/blob/2c5009cd927402f306463278f3224ea17c533f8c/resources/boost/skills/type-bridge-enum-generation/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, Frontend Developer, Full-Stack Developer
Specialties: Backend, Frontend
Tools: Laravel
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: ad8eb5ddcf05ca362615257569416bf89d1a908fdcc022a4c563e0821fa04d89
