PHPackages                             paneon/php-to-typescript-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. paneon/php-to-typescript-bundle

ActiveLibrary

paneon/php-to-typescript-bundle
===============================

Symfony-Bundle to use the PHP to Typescript library

v2.3.0(2mo ago)110.1k↓100%MITPHPPHP ^8.1

Since Dec 14Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Paneon/php-to-typescript-bundle)[ Packagist](https://packagist.org/packages/paneon/php-to-typescript-bundle)[ RSS](/packages/paneon-php-to-typescript-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (8)Versions (11)Used By (0)

PHP Classes to TypeScript Bundle
================================

[](#php-classes-to-typescript-bundle)

[![Build](https://github.com/Paneon/php-to-typescript-bundle/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/Paneon/php-to-typescript-bundle/actions/workflows/main.yml)[![Latest Stable Version](https://camo.githubusercontent.com/00898283015cd7e781d7a09891ad5fe949e12366a5034268668141a8cdbb825f/68747470733a2f2f706f7365722e707567782e6f72672f70616e656f6e2f7068702d746f2d747970657363726970742d62756e646c652f762f737461626c65)](https://packagist.org/packages/paneon/php-to-typescript-bundle)[![Total Downloads](https://camo.githubusercontent.com/09db9db851f3bd90be1b5461771e1a34a3b1f47f801ce7baf28d8eb9e3f2cb14/68747470733a2f2f706f7365722e707567782e6f72672f70616e656f6e2f7068702d746f2d747970657363726970742d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/paneon/php-to-typescript-bundle)[![License](https://camo.githubusercontent.com/e5c0a9d94ad0e99780f7637be521a614f246abf8c4becba5eb3506e21aee6f2d/68747470733a2f2f706f7365722e707567782e6f72672f70616e656f6e2f7068702d746f2d747970657363726970742d62756e646c652f6c6963656e7365)](https://packagist.org/packages/paneon/php-to-typescript-bundle)

A Symfony bundle that adds a command to extract [TypeScript interface](https://www.typescriptlang.org/docs/handbook/interfaces.html)from PHP classes. Based on [the example from Martin Vseticka](https://stackoverflow.com/questions/33176888/export-php-interface-to-typescript-interface-or-vice-versa?answertab=votes#tab-top)this bundle uses [the PHP-Parser library](https://github.com/nikic/PHP-Parser) and docblock annotations.

TypeScript is a superscript of JavaScript that adds strong typing and other features on top of JS. Automatically generated classes can be useful, for example when using a simple JSON API to communicate to a JavaScript client. This way you can get typing for your API responses in an easy way.

Feel free to build on this or use as inspiration to build something completely different.

Installation
------------

[](#installation)

As a Symfony bundle you'll need to start by adding the package to your project with Composer:

```
composer require paneon/php-to-typescript-bundle
```

Usage of the Command 'typescript:generate'
------------------------------------------

[](#usage-of-the-command-typescriptgenerate)

The purpose of the generate Command is to create TypeScript definitions for all Classes in your source root which are under your immediate control (i.e. You can change their source). It will only affect classes which have the *@TypeScriptInterface*-Annotation.

```
php bin/console typescript:generate
```

The command scans directories recursively for all `.php` files. It will only generate Type Definitions (interfaces) for files with the appropriate annotation. The default parameters will scan for alle PHP Classes inside "src/" and output them as TypeScript Interfaces into "assets/js/interfaces/" while keeping the relative directory structure.

#### Examples:

[](#examples)

Source FileOutput Filesrc/Model/Person.phpassets/js/interfaces/Model/Person.d.tssrc/Example.phpassets/js/interfaces/Example.d.ts#### Example source file:

[](#example-source-file)

```
