spatie / laravel-typescript-transformer
Transform your PHP structures to TypeScript types
Fund package maintenance!
spatie
spatie.be/open-source/support-us
Installs: 2 260 138
Dependents: 28
Suggesters: 0
Security: 0
Stars: 245
Watchers: 7
Forks: 20
Open Issues: 1
Requires
- php: ^8.1
- illuminate/console: ^8.83|^9.30|^10.0|^11.0
- spatie/laravel-package-tools: ^1.12
- spatie/typescript-transformer: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.4
- nesbot/carbon: ^2.63
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- pestphp/pest: ^1.22|^2.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
- spatie/data-transfer-object: ^2.0
- spatie/enum: ^3.0
- spatie/laravel-model-states: ^1.6|^2.0
- spatie/pest-plugin-snapshots: ^1.1|^2.0
- spatie/phpunit-snapshot-assertions: ^4.2|^5.0
- spatie/temporary-directory: ^1.2
README
Transform PHP types to TypeScript
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 = { id: 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've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.