- What is abetwothree/laravel-ts-publish used for?
- It is a Laravel package that generates and publishes TypeScript definitions from your Laravel application. It helps keep PHP models, resources, enums, and relations aligned with a TypeScript frontend instead of hand-maintaining interfaces. You run it through an Artisan command and configure where the generated TypeScript output is written.
- How do I install and configure laravel-ts-publish in a Laravel app?
- Install it with Composer using the package name abetwothree/laravel-ts-publish, then publish and adjust its configuration for your output paths and model directories. The package is framework-native, so setup is handled through Laravel configuration and the ts:publish Artisan command. Check the repository README for the exact service provider or config publishing steps for your version.
- How do I generate TypeScript definitions with the ts:publish command?
- Run php artisan ts:publish from your Laravel application to generate and publish TypeScript definitions to your configured output paths. In v2.7.0, --only-resources and --source runs now type morphTo unions consistently with full runs. Wire the command into local build scripts or CI wherever generated types are produced.
- Which Laravel and PHP versions does laravel-ts-publish support?
- The package is built for Laravel applications with a TypeScript frontend, but the README and Composer constraints are the source of truth for supported PHP, Laravel, Node, and TypeScript versions. Before upgrading, verify those constraints against your project, especially for v2.7.0. The release notes do not call out breaking application-code changes, but you should still confirm compatibility.
- How can I exclude models, enums, or directories from generated TypeScript?
- Use the package's models.excluded and models.included settings, plus attributes such as #[TsExclude] and #[TsEnum], to narrow or rename the generated surface. You can also manage related model coverage with models.additional_directories when models need metadata or Vite plugin updates. Review exclusions intentionally because auto-published related models can expand the generated type surface.
- What changed in laravel-ts-publish v2.7.0?
- v2.7.0 improves the generated TypeScript contract so files reference files the run actually writes, auto-publishes related models when needed, gives duplicate class names distinct aliases, and makes the global declaration file parse reliably. It also improves namespace casing and surfaces enum and class name collisions as warnings. Expect generated output diffs after upgrading even though no breaking application-code changes are called out.
- Will upgrading to laravel-ts-publish v2.7.0 break my frontend TypeScript imports?
- The upgrade is likely feasible without application-code changes, but generated output will change in many projects due to auto-published related models, improved aliasing, and corrected namespace casing. If your frontend tsconfig consumes the global declaration file, check whether namespace casing changed from kebab-case to camelCase and whether existing imports still resolve. Run ts:publish, inspect the diff, and run the frontend TypeScript compiler after upgrading.
- Should I commit generated TypeScript files or run ts:publish during the build?
- Either approach can work as long as generated types are produced wherever your frontend build or CI expects them. Many teams run ts:publish in CI and local build scripts, and some commit the generated artifacts for stable frontend consumption. Whichever you choose, regenerate all affected type outputs for monorepos or multiple frontends before merge.
- How does laravel-ts-publish handle duplicate class names and enum collisions?
- In v2.7.0, duplicate class names receive distinct aliases so generated files can reference the correct definitions. Enum and class name collisions can still occur and are surfaced as warnings rather than silently fixed. Use enum aliases or exclusion settings where the generated surface needs to be intentionally narrowed or renamed.
- Can I use laravel-ts-publish with Vite and a global TypeScript declaration file?
- Yes, the package fits Laravel plus a TypeScript frontend using Vite or a similar build pipeline, and it can generate a global declaration file for your tsconfig to consume. Confirm that generated files satisfy your frontend tsconfig and that namespace casing changes do not break existing imports. For related models that need metadata files or Vite plugin updates, add them to models.additional_directories.