- How do I install irontec/typescript-generator-bundle in a Laravel project?
- Install it with Composer and run the bundle's generator command from your host or container. Because it is published as a Symfony bundle, verify the supported PHP/Laravel matrix and any Symfony framework dependencies before adding it to a Laravel app. In practice, most teams treat it as a build-time CLI and write generated files into a front-end source directory such as resources/js/types/generated.
- Does this package work with Laravel and Inertia or a separate SPA front end?
- It is designed as a build-time codegen tool, so it fits Laravel apps that use Inertia with Vue or React, or a separate SPA consuming an API. It does not add a runtime dependency to your application container. You run generation during development or CI and commit or review the resulting TypeScript definitions.
- How does the #[TypeScriptMe] attribute control TypeScript generation?
- In 1.0.0, participation is opt-in via the #[TypeScriptMe] PHP attribute placed on the class you want to expose. That keeps generation colocated with the PHP model, DTO, or value object and lets you pilot one bounded context without touching unrelated code. Classes without the attribute are not part of the generated contract.
- Can I configure the output directory and naming of generated TypeScript files?
- Yes. The bundle provides flexible output and naming configuration for repeatable generation, so you can target a directory inside your front-end source tree. A common setup is resources/js/types/generated with a stable naming convention. Confirm where the generator expects package.json, because the 1.0.0 notes mention a guard around package.json creation and non-standard layouts can affect it.
- Does it support nullable properties, inheritance, arrays, and collections?
- The package supports nullable properties, inheritance, and collection types where applicable, according to its overview. Type mappings for scalars, dates, arrays, and custom classes are configurable. Coverage of backed enums, generics, Carbon, and Eloquent-specific casts should be validated against your real classes before relying on it broadly.
- What happens when the generator cannot determine a PHP property type?
- Version 1.0.0 introduced a TypeScriptBaseInterface fallback for unknown property types, which prevents generation from failing. The tradeoff is that it can emit a widened or loose TypeScript contract that silently diverges from the PHP truth. Treat generated files as reviewable artifacts and add checks for unexpected base-interface usage.
- How can I detect drift between PHP classes and generated TypeScript types in CI?
- The recommended pattern is to regenerate in CI and fail the build if the generated output differs from what is committed. The generator can run from the host or a container, which helps pin the PHP version in Docker-based dev and CI environments. Pin the exact package version and diff generated output on every bump, because the output shape can change between releases.
- Is version 1.0.0 stable enough for production use?
- Version 1.0.0 is the first stable cut, but the release notes describe foundational fixes rather than polish, which suggests the type-mapping surface is still being discovered. Maintainer count, release cadence, and issue responsiveness are unverified. A safe approach is to pilot one bounded context, pin 1.0.0 exactly, and review generated diffs before expanding.
- How does it handle Eloquent models, casts, accessors, and relationships?
- The context does not confirm schema-aware mapping; the generator appears to work from PHP classes rather than consulting the database schema. That means Eloquent magic properties, casts, accessors, and relations may need explicit DTOs or annotations to produce precise TypeScript types. Validate these cases early and avoid generating from Eloquent models until the mapping rules are proven.
- What alternatives should I consider for generating TypeScript types from PHP or Laravel code?
- Alternatives include hand-written TypeScript interfaces, OpenAPI or JSON Schema generators, and other PHP-to-TypeScript codegen tools. This bundle's differentiator is opt-in generation via #[TypeScriptMe] and configurable mappings for Symfony and PHP classes. Evaluate it on type fidelity, enum and collection handling, and whether CI drift detection fits your workflow.