{"id":19697137,"url":"https://github.com/janit/typescriptgeneratorbundle","last_synced_at":"2025-04-29T11:32:22.240Z","repository":{"id":56996461,"uuid":"109490918","full_name":"janit/TypeScriptGeneratorBundle","owner":"janit","description":"A Symfony Bundle that adds a command to extract TypeScript interfaces from PHP classes","archived":false,"fork":false,"pushed_at":"2020-06-09T18:23:37.000Z","size":12,"stargazers_count":16,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T04:25:36.090Z","etag":null,"topics":["php","symfony","typescript"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-04T11:54:38.000Z","updated_at":"2024-03-15T10:43:43.000Z","dependencies_parsed_at":"2022-08-21T14:10:11.212Z","dependency_job_id":null,"html_url":"https://github.com/janit/TypeScriptGeneratorBundle","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2FTypeScriptGeneratorBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2FTypeScriptGeneratorBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2FTypeScriptGeneratorBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2FTypeScriptGeneratorBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janit","download_url":"https://codeload.github.com/janit/TypeScriptGeneratorBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251494090,"owners_count":21598233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","symfony","typescript"],"created_at":"2024-11-11T19:37:18.899Z","updated_at":"2025-04-29T11:32:19.128Z","avatar_url":"https://github.com/janit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PHP Classes to TypeScript Interfaces Generator Bundle\n======\n\nA 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 annotations. This is currently very basic feature wise, but it does work.\n\nTypeScript 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.\n\nThis is currently tightly coupled to the Symfony Framework, but could be extracted. Feel free to build on this or use as inspiration to build something completely different.\n\n## Installation\n\nAs a Symfony bundle you'll need to start by add the package to your project with composer:\n\n```\n$ composer req janit/typescript-generator-bundle\n```\n\nAfter this you'll need to activate the bundle in your `app/AppKernel.php` file:\n\n```\nnew Janit\\TypeScriptGeneratorBundle\\TypeScriptGeneratorBundle()\n```\n\nOnce this is done you should have the added command in place in your console and you can run:\n\n```\n$ php bin/console typescript:generate-interfaces\n```\n\nThis will yield an error because the command expects `fromDir` as a parameter on where to scan for PHP classes.\n\nNOTE: These instructions are for Symfony Standard Edition (3.3), but the bundle should work with Symfony Flex as well.\n\n## Usage\n\nThe command scans directories recursively for all `.php` files. It will only generate Type Definitions (interfaces) for files with appropriate annotations.\n\nTo generate interfaces, create a new class in `src/AppBundle/Entity/Person.php` and enter the following:\n\n```php\n\u003c?php\n\nnamespace AppBundle\\Entity;\n\n/**\n * @TypeScriptMe\n */\nclass Person\n{\n    /**\n     * @var string\n     */\n    public $firstName;\n\n    /**\n     * @var string\n     */\n    public $lastName;\n\n    /**\n     * @var int\n     */\n    public $age;\n}\n```\n\nOnce this is in place you can run the command with the argument `src/`:\n\n```\n$ php bin/console typescript:generate-interfaces src/\n```\n\nThis will generate the following file `typescript/Person.d.ts` with the following content:\n\n```\ninterface Person {\n  firstName: string,\n  lastName: string,\n  age: number\n}\ndeclare var Person: Person;\n\n```\n\nIf you provide another argument (`toDir`) you can change the target directory to something else.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanit%2Ftypescriptgeneratorbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanit%2Ftypescriptgeneratorbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanit%2Ftypescriptgeneratorbundle/lists"}