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
This package allows you to convert PHP classes to TypeScript.
This class...
class User
{
public int $id;
public string $name;
public ?string $address;
}
... will be converted to this TypeScript type:
export type User = {
id: number;
name: string;
address: string | null;
}
Here's another example.
class Languages extends Enum
{
const TYPESCRIPT = 'typescript';
const PHP = 'php';
}
The Languages
enum will be converted to:
export type Languages = 'typescript' | 'php';