This is the documentation for
v1 but the latest version is
v2
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/typescript-transformer
##Framework agnostic
$config = TypeScriptTransformerConfig::create()
->searchingPath(__DIR__ . '/src') // path where your PHP classes are
->transformers([MyclabsEnumTransformer::class]) // list of transformers
->outputFile(__DIR__ . '/js/generated.d.ts'); // file where TypeScript type definitions will be written
This is the minimal required configuration that should get you started. There are some more configuration options, but we'll go over these later in the documentation.
Let's use this configuration to start the transformation process:
TypeScriptTransformer::create($config)->transform();
That's it! All the enum classes with a @typescript
annotation are now transformed to TypeScript.
Classes not converted? You probably should write your own transformers.
##Laravel
Using Laravel? Then you can use a Laravel config file, more info about that here.