ts2php is a TypeScript to PHP transpiler (v0.30.3, latest release Jan 2021) that converts TypeScript/JavaScript code into PHP. It aims to enable code sharing between front-end and back-end by translating TypeScript into PHP. Key differentiators: it supports a large subset of TypeScript features including classes, interfaces, generics, async/await, and standard library polyfills. It is read-only (not a bidirectional bridge) and generates PHP code that can be used in any PHP project. Releases have slowed, indicating maintenance mode. Requires TypeScript ^3.7.0 as a peer dependency.
npm install ts2phpNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Transpiles a simple TypeScript function to PHP using ts2php with type declarations enabled.
Install TypeScript 3.7.0 or later: npm install typescript@^3.7.0
Use ESM imports: import ts2php from 'ts2php';
Use transpile() instead.
Use ESM import: import ts2php from 'ts2php';
Install typescript: npm install typescript@^3.7.0
Use valid modules option: 'commonjs' or 'esm' (not 'amd' or 'system').