Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Typescript Generator Bundle Laravel Package

irontec/typescript-generator-bundle

Symfony bundle that generates TypeScript definitions from PHP classes, helping keep backend models and frontend types in sync. Automate interface generation for APIs and DTOs, improve IDE autocomplete, and reduce type duplication. Ideal for Symfony apps needing consistent frontend/backend contracts.

View on GitHub
Deep Wiki
Context7

Getting Started

TypeScriptMe 1.0.0 is a Laravel/PHP package for generating TypeScript interfaces from PHP classes, with 1.0.0 adding an attribute-driven entry point via TypeScriptMe.

Minimal setup:

  1. Install the package with Composer and publish any package config if prompted:

    composer require <vendor>/typescriptme
    php artisan vendor:publish --tag=typescriptme-config
    
  2. Confirm the generation command is available:

    php artisan list
    
  3. Annotate the PHP class you want reflected into TypeScript:

    use TypeScriptMe;
    
    #[TypeScriptMe]
    class UserData
    {
        public int $id;
        public string $name;
        public ?string $email;
    }
    
  4. Run the package’s generation command, then inspect the generated .ts output. In 1.0.0 this can run from the host or inside a container, so Laravel Sail/Docker users can use either:

    php artisan typescriptme:generate
    # or
    sail artisan typescriptme:generate
    

First practical use case: expose a small DTO or API response class as a TypeScript interface so frontend code can consume the same shape Laravel returns.

Implementation Patterns

Use TypeScriptMe where PHP and TypeScript share a contract: API resources, DTOs, form payloads, and Inertia/Livewire data objects. The new #[TypeScriptMe] attribute makes this explicit and keeps generation close to the class definition.

Typical workflow:

  • Define a DTO or response object with typed public properties.
  • Add #[TypeScriptMe] to the class.
  • Run generation as part of local development.
  • Import the generated interface in frontend code.
  • Optionally run generation in CI and fail if generated files are out of date.

Example contract class:

use TypeScriptMe;

#[TypeScriptMe]
class PostSummary
{
    public int $id;
    public string $title;
    public string $slug;
    public ?string $publishedAt;
}

For legacy or loosely typed models, 1.0.0’s TypeScriptBaseInterface fallback is useful: if a property type cannot be resolved, the package can emit a base interface instead of failing hard. Use that as a bridge, not as the final state. Add casts, docblocks, or typed properties where possible so frontend consumers get precise types.

Container/host execution pattern:

  • Standardize one invocation in a Composer script or Makefile, for example composer typescript or make types.
  • Use the same command inside Sail/container environments to avoid path and permission differences.
  • Run generation after changing DTOs, model casts, or API resource shapes.

CI pattern:

php artisan typescriptme:generate
git diff --exit-code -- resources/js/types

This catches drift between PHP contracts and committed TypeScript definitions.

Gotchas and Tips

  • package.json must be creatable. 1.0.0 prevents interface generation if the package cannot create package.json, so check write permissions and the configured output path before debugging type generation.
  • Unknown PHP property types now fall back to TypeScriptBaseInterface. This avoids hard failures, but it can silently produce weak TypeScript types. Treat fallback output as a signal to improve PHP typing.
  • Attribute discovery matters. If a class is not picked up, verify the #[TypeScriptMe] attribute is imported correctly, the class is autoloadable, and the generation command is scanning the expected paths.
  • Host vs container execution can produce different absolute paths. If generation works locally but not in Sail/Docker, compare working directory, volume mounts, and output permissions.
  • Decide whether generated TypeScript is committed. Committing it makes frontend builds deterministic but requires CI drift checks; ignoring it requires generation before every frontend build.
  • Pin the package version in composer.json. 1.0.0 is the first stable release line, so avoid floating constraints in production until the API surface has settled.
  • When debugging, start with the package config, the php artisan list command name, and verbose command output. Clear Laravel config cache after changing package settings:
    php artisan config:clear
    
  • Use the attribute on small, purpose-built DTOs rather than large Eloquent models where possible. It keeps generated interfaces stable and avoids leaking persistence concerns into frontend contracts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums