- How do I install and set up Runtype in a Laravel project?
- Install vagebond/runtype as a Composer dev dependency and wire its generation command into an Artisan target or CI step. Run the generator against the Resources you want to expose to TypeScript, then commit the emitted interfaces to your frontend source tree or emit them during a build. Keep the first rollout small, such as one bounded domain, before expanding to the full API surface.
- Which Laravel and PHP versions does Runtype support?
- The package is built for Laravel applications, but you should confirm the supported Laravel major and PHP version in its composer.json and README before adopting it. Laravel ships annually, so a small codegen package must track new releases; validate against your exact Laravel 9, 10, 11, or 12 matrix. Pin the version you test and review the maintainer's stated support policy.
- Does Runtype handle whenLoaded, when, mergeWhen, and conditional additional fields in JsonResources?
- Conditional inclusion is the main fidelity risk for any Resource-driven TypeScript generator, because the runtime JSON shape can vary per request. Runtype generates from Laravel Resources, so you should verify how it represents whenLoaded, when, mergeWhen, and conditional additional() output in your own Resources. Contract-test a few real API responses against the generated interfaces before relying on them in production.
- Can Runtype generate TypeScript from Laravel Resources only, or does it need Eloquent models?
- Runtype is positioned around Laravel Models and Resources, and the recommended seam is the JsonResource transformation layer rather than raw database schema. Generating from Resources is preferable because Resources often rename, reshape, paginate, and conditionally include fields that models do not represent. Confirm in the docs whether a given command accepts Resources alone or also couples to models for your use case.
- How are PHP enums, Carbon dates, and casts mapped to TypeScript by Runtype?
- Mapping PHP types to TypeScript is a key evaluation point: backed enums should typically become string or numeric unions, and dates should become strings in the JSON payload. Casts such as money or decimal may need explicit handling because their JSON representation can differ from the PHP type. Test your actual enum, Carbon, and cast combinations against generated output rather than assuming default mappings.
- Is Runtype output deterministic and can I use it as a CI check for drifted types?
- Deterministic, idempotent output is essential if you want to run the generator in CI and fail on diffs. The TPM assessment flags drift as a silent risk for codegen tools, so verify whether Runtype supports a dry-run or diff mode and whether repeated runs produce identical files. A CI gate that regenerates and compares output is the safest way to prevent stale TypeScript from merging.
- Can I extend or override Runtype-generated TypeScript interfaces?
- You should establish an escape hatch before adopting any generator, because generated files should not be hand-edited. A practical pattern is to emit into a types/generated directory and compose or extend those interfaces in hand-written application types. Check whether Runtype supports overrides, custom templates, or configuration for naming and optionality so your extensions survive regeneration.
- Is Runtype production-ready given its low star count and single maintainer?
- The package is MIT licensed and technically low-friction, but the TPM assessment notes thin maturity signals: few stars, no dependents, and a single maintainer. That is a real risk for a code-generation role because abandonment can leave you with a broken generator and generated files you cannot safely hand-maintain. Pilot it on a bounded domain, keep generated output reviewable, and have a plan to replace or vendor the generator if needed.
- What are alternatives to Runtype for TypeScript types from Laravel APIs?
- Alternatives include schema-first contracts such as OpenAPI or GraphQL with generated TypeScript clients, or hand-written types backed by contract tests. Runtype's advantage is aligning with Laravel JsonResources instead of introducing a separate schema registry, which avoids two sources of truth for Resource-shaped APIs. Choose it when your API is Resource-driven and your frontend is TypeScript; choose OpenAPI or GraphQL when the organization already standardizes on those contracts.
- How should I test that Runtype-generated types match real Laravel API responses?
- Add a contract test that captures a real JSON response from your Laravel endpoint and validates it against the generated TypeScript interface at runtime, for example with zod or io-ts. Cover representative cases: nested Resources, paginated collections, whenLoaded relations, and optional fields. Run that test in CI alongside a regeneration diff check so both runtime shape and type drift are caught.