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.
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:
Install the package with Composer and publish any package config if prompted:
composer require <vendor>/typescriptme
php artisan vendor:publish --tag=typescriptme-config
Confirm the generation command is available:
php artisan list
Annotate the PHP class you want reflected into TypeScript:
use TypeScriptMe;
#[TypeScriptMe]
class UserData
{
public int $id;
public string $name;
public ?string $email;
}
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.
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:
#[TypeScriptMe] to the class.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:
composer typescript or make types.CI pattern:
php artisan typescriptme:generate
git diff --exit-code -- resources/js/types
This catches drift between PHP contracts and committed TypeScript definitions.
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.TypeScriptBaseInterface. This avoids hard failures, but it can silently produce weak TypeScript types. Treat fallback output as a signal to improve PHP typing.#[TypeScriptMe] attribute is imported correctly, the class is autoloadable, and the generation command is scanning the expected paths.composer.json. 1.0.0 is the first stable release line, so avoid floating constraints in production until the API surface has settled.php artisan list command name, and verbose command output. Clear Laravel config cache after changing package settings:
php artisan config:clear
How can I help you explore Laravel packages today?