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
When using the @typescript
annotation, the PHP class's name will be used for the TypeScript type:
/** @typescript */
class Languages extends Enum{
const en = 'en';
const nl = 'nl';
const fr = 'fr';
}
The package will produce the following TypeScript:
export type Languages = 'en' | 'nl' | 'fr';
You can also give the type another name:
/** @typescript Talen **/
class Languages extends Enum{}
Now the transformed TypeScript looks like this:
export type Talen = 'en' | 'nl' | 'fr';
Want to define a specific transformer for the file? You can use the following annotation:
/**
* @typescript
* @typescript-transformer \Spatie\TypeScriptTransformer\Transformers\SpatieEnumTransformer::class
*/
class Languages extends Enum{}
It is also possible to transform types without adding annotations. You can read more about it here.