Runtype

TypeScript interfaces from your Laravel models and resources, generated with one Artisan command.

Visit runtype.vagebond.nl GitHub composer require vagebond/runtype --dev
Made by
Vagebond
Type
Open source
Stack
PHP, Laravel, TypeScript
A Laravel resource next to the TypeScript type that Runtype generates from it.

From resource to type

Runtype reads the resources in app/Http/Resources and writes one TypeScript type for each of them. A conditional attribute becomes an optional property.

php artisan runtype:generate

Models and resources

Runtype has a converter for models, a converter for resources and a default converter for all other classes. The config file says which converter to use for each class.

'converters' => [
    JsonResource::class => ResourceConverter::class,
    Model::class => ModelConverter::class,
],

Extend it

Write your own converter. Add a modifier to set the properties that Runtype cannot detect, or replace a PHP type, such as DateTime, with a TypeScript type.

Stack

  • PHP
  • Laravel
  • TypeScript
  • Pest