Download the PHP package codemystify/laravel-types-generator without Composer
On this page you can find all versions of the php package codemystify/laravel-types-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codemystify/laravel-types-generator
More information about codemystify/laravel-types-generator
Files in codemystify/laravel-types-generator
Package laravel-types-generator
Short Description Simplified TypeScript types generator for Laravel applications with developer-defined structure system
License MIT
Homepage https://github.com/codemystify/laravel-types-generator
Informations about the package laravel-types-generator
Laravel Types Generator
I got tired of manually writing TypeScript types for my Laravel APIs, so I built this. It's simple: you tell it exactly what your data looks like, and it generates clean TypeScript interfaces. No magic, no guessing, just straight-forward type generation.
What This Actually Does
You add an attribute to your Laravel classes (like API resources), define the structure, run a command, and get TypeScript files. That's it.
Installation
If you want to customize the config:
Quick Example
Here's how I use it in my Laravel API resources:
Run the command:
Get this TypeScript file:
How to Define Types
Basic Types
Optional Fields
For fields that might not be present:
Nullable Fields
For fields that can be null:
Arrays
Union Types
Real Example: Blog Post API
Here's how I handle a typical blog post resource:
This generates two clean interfaces:
Commands
Generate Types
Preview Without Writing Files
Generate Specific Group
Using Groups
I organize my types with groups:
Then generate specific groups:
File Organization
All generated files go to resources/js/types/generated/
by default:
The index.ts
file automatically exports everything:
So in your React/Vue components:
Configuration
The defaults work fine, but you can customize:
Practical Tips
1. Start Simple
Don't try to define everything at once. Start with basic types and add complexity as needed.
2. Mirror Your API Exactly
The structure should match exactly what your API returns. Don't overthink it.
3. Use Optional vs Nullable Correctly
optional: true
- field might not exist in the responsenullable: true
- field exists but can be null
4. Handle Pagination
5. Keep It DRY with Shared Types
Define common types once and reuse them:
Why I Built This
I tried other solutions but they were either:
- Too magic (trying to guess types from code)
- Too complicated (requiring tons of configuration)
- Too unreliable (breaking when Laravel code changed)
This approach is explicit and predictable. You define exactly what you want, and you get exactly that. No surprises.
Troubleshooting
Types not generating?
- Make sure you're using the attribute in classes that the scanner can find
- Check that your
sources
config includes the right directories - Run with
--dry-run
to see what would be generated
Import errors in TypeScript?
- The generator creates proper import statements automatically
- Make sure you're importing from the right path
- Check that the
index.ts
file was generated
Want to disable the package in production?
The attributes have no runtime impact, but if you want to remove them:
That's it! Simple, predictable TypeScript type generation for Laravel. No magic, just the types you define.
All versions of laravel-types-generator with dependencies
illuminate/console Version ^11.0|^12.0
illuminate/filesystem Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0