spatie / laravel-typescript-transformer by spatie

Transform your PHP structures to TypeScript types
1,279,493
200
7
Package Data
Maintainer Username: spatie
Maintainer Contact: ruben@spatie.be (Ruben Van Assche)
Package Create Date: 2020-06-29
Package Last Update: 2024-04-04
Home Page: https://docs.spatie.be/typescript-transformer/v2/introduction/
Language: PHP
License: MIT
Last Refreshed: 2024-04-27 03:14:26
Package Statistics
Total Downloads: 1,279,493
Monthly Downloads: 100,826
Daily Downloads: 3,899
Total Stars: 200
Total Watchers: 7
Total Forks: 18
Total Open Issues: 1

Transform PHP types to TypeScript

Latest Version on Packagist GitHub Tests Action Status Styling Psalm Total Downloads

Always wanted type safety within PHP and TypeScript without duplicating a lot of code? Then you will like this package! Let's say you have an enum:

class Languages extends Enum
{
    const TYPESCRIPT = 'typescript';
    const PHP = 'php';
}

Wouldn't it be cool if you could have an automatically generated TypeScript definition like this:

export type Languages = 'typescript' | 'php';

This package will automatically generate such definitions for you, the only thing you have to do is adding this annotation:

/** @typescript **/
class Languages extends Enum
{
    const TYPESCRIPT = 'typescript';
    const PHP = 'php';
}

You can even take it a bit further and generate TypeScript from classes:

/** @typescript */
class User
{
    public int $id;

    public string $name;

    public ?string $address;
}

This will be transformed to:

export type User = {
    int: number;
    name: string;
    address: string | null;
}

Want to know more? You can find the documentation here.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.