Skip to content

Conversation

@innocenzi
Copy link
Member

@innocenzi innocenzi commented Jan 17, 2026

This pull request adds support for generating TypeScript definitions out of PHP classes and enums.

Documentation: https://github.com/tempestphp/tempest-framework/blob/feat/typescript-codegen/docs/2-features/18-typescript.md


Running the generate:typescript-types command will create a types.d.ts file at the root of the project, with namespaced definitions:

/*
|----------------------------------------------------------------
| This file contains TypeScript definitions generated by Tempest.
|----------------------------------------------------------------
*/

export namespace App {
  export interface Settings {
    theme: Theme.Theme;
    sidebar_open: boolean;
    last_edited_at: string;
  }
  export interface Permission {
    name: string;
  }
  export interface User {
    settings: Settings;
    permissions: Permission[];
  }
}

export namespace App.Theme {
  export type Theme = 'dark' | 'light';
}

This is configurable by creating a config returning NamespacedTypeScriptGenerationConfig or DirectoryTypeScriptGenerationConfig. The latter generates a directory structure in ./types that's importable instead of .d.ts files:

types
└── app
    ├── index.ts
    └── theme
        └── index.ts

To mark a class for generation, it needs to have a #[AsType] attribute. However, I plan to implement heuristics (eg. the class only has public readonly properties) to automatically convert classes without having to add an attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants