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

Typescript Transformer Laravel Package

spatie/typescript-transformer

Automatically generate TypeScript definitions from your PHP/Laravel code. spatie/typescript-transformer scans classes and types, then outputs .d.ts files so your frontend stays in sync with backend models, DTOs and enums with minimal manual typing.

View on GitHub
Deep Wiki
Context7

title: Special attributes weight: 3

Classes can have attributes that change the way they are transformed, let's go through them.

Using the #[TypeScript] attribute is not only a way to tell typescript-transformer to transform a class, but it can also be used to change the name of the transformed class:

#[TypeScript(name: 'UserWithoutEmail')]
class User
{
    public int $id;
    public string $name;
}

This will transform the User class to UserWithoutEmail in TypeScript.

export type UserWithoutEmail = {
    id: number;
    name: string;
}

Each type will be located somewhere either being a file when using the ModuleWriter or in a single file when using the GlobalNamespaceWriter. The location of the type can be changed by using the #[TypeScript] attribute:

#[TypeScript(location: ['Data', 'Users'])]
class User
{
    public int $id;
    public string $name;
}

This will transform as such:

declare namespace Data.Users {
    export type User = {
        id: number;
        name: string;
    };
}

By default, the location is based on the namespace of the PHP class.

It is possible to completely remove a class from the TypeScript output by using the #[Hidden] attribute:

#[Hidden]
enum Members: string
{
    case John = 'john';
    case Paul = 'paul';
    case George = 'george';
    case Ringo = 'ringo';
}

This is particularly useful when using the EnumTransformer and you want to hide certain enums from the TypeScript.

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor