Weave Code
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

Laravel Typescript Transformer Laravel Package

spatie/laravel-typescript-transformer

Convert PHP classes, enums, and more into TypeScript types automatically. Uses attributes to generate TS from your Laravel code, supports nullable and complex types, generics, and even TypeScript functions—keeping your backend and frontend types in sync.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Type Safety for Full-Stack Teams: Enables seamless integration between PHP backend (Laravel) and TypeScript frontend by auto-generating type definitions for models, enums, controllers, and routes. Reduces manual type maintenance and improves developer experience.
  • Accelerated Frontend Development: Eliminates repetitive type definition work for API responses, requests, and route parameters, allowing frontend teams to focus on UI/UX while maintaining type safety.
  • Laravel Ecosystem Expansion: Supports modern Laravel features like laravel-data, enums, and generics, making it ideal for projects using these patterns (e.g., DTOs, API resources, or domain-driven design).
  • Build vs. Buy Decision: Justifies buying this package over custom solutions for teams already using Laravel + TypeScript, as it handles edge cases (e.g., route helpers, nested types, and Laravel-specific quirks like Carbon or Collection).
  • Roadmap Priorities:
    • Phase 1: Integrate into CI/CD pipelines for auto-generated types during deployments.
    • Phase 2: Extend to support GraphQL schemas or gRPC services if the backend evolves.
    • Phase 3: Explore custom transformers for domain-specific types (e.g., payment processing objects).

When to Consider This Package

  • Adopt if:

    • Your stack uses Laravel 10+ and TypeScript (e.g., Vue/React/Inertia.js frontends).
    • You maintain complex PHP types (DTOs, enums, generics) that need frontend type coverage.
    • Your team struggles with manual type synchronization between backend and frontend.
    • You want automated route typing (e.g., route('user.profile') with parameter validation).
    • You’re using laravel-data or Laravel’s native enums and need TypeScript equivalents.
  • Look elsewhere if:

    • You’re not using Laravel (this is Laravel-specific).
    • Your frontend is not TypeScript-based (e.g., plain JavaScript or another language).
    • You need runtime type generation (this is compile-time only).
    • Your project is small-scale with minimal PHP-to-TypeScript type mapping needs.
    • You require custom serialization logic beyond what the package supports (e.g., nested API responses with dynamic keys).

How to Pitch It (Stakeholders)

For Executives:

"This package bridges our Laravel backend and TypeScript frontend by auto-generating type definitions for models, routes, and controllers—saving our dev team hundreds of hours annually on manual type maintenance. It’s a low-risk, high-reward investment that improves code quality, reduces bugs, and accelerates frontend development. For example, a User model in PHP becomes a strongly typed User interface in TypeScript, enabling IDE autocompletion and runtime checks. The package is battle-tested (383 stars, MIT license) and maintained by Spatie, a trusted Laravel ecosystem contributor."

ROI:

  • Reduced toil: Eliminates syncing types between PHP and TypeScript.
  • Faster onboarding: New frontend devs get type safety out of the box.
  • Lower risk: Catches type mismatches early (e.g., API response shape changes).

For Engineering Teams:

*"This solves our biggest pain point: keeping TypeScript types in sync with Laravel’s evolving backend. Here’s how we’ll leverage it:

  1. Auto-generate types for all DTOs/enums: Annotate PHP classes with #[TypeScript] and run php artisan typescript:transform to output .d.ts files.
  2. Typed routes: Generate a route() helper with autocompletion for all Laravel routes (e.g., route('posts.store')).
  3. Controller actions: TypeScript will know the exact request/response shapes for every controller method, thanks to Laravel’s reflection.
  4. Watch mode: Run php artisan typescript:watch to auto-regenerate types during development.

Why this over custom solutions?

  • Handles Laravel quirks (e.g., Carbon, Collection, laravel-data).
  • Supports generics, unions, and nested types out of the box.
  • Actively maintained with Laravel 10+ support.

Next steps:

  • Add spatie/laravel-typescript-transformer to composer.json.
  • Configure the service provider in AppServiceProvider.
  • Run php artisan typescript:install to set up the watcher.
  • Start annotating critical PHP classes with #[TypeScript].

Example:

// PHP (Laravel)
#[TypeScript]
class CreatePostRequest {
    public string $title;
    public string|null $content;
}
// Auto-generated TypeScript
export type CreatePostRequest = {
    title: string;
    content: string | null;
};
```"*

**Key benefits for devs**:
- **No more "any" types**: Frontend gets accurate, up-to-date types.
- **Fewer API docs**: Types serve as self-documenting contracts.
- **CI/CD friendly**: Types are generated as part of the build process.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony