TypoWay is a Laravel package that generates TypeScript route definitions, including API endpoints, URLs, and Inertia.js form helpers. It provides a strongly typed way to work with routes in TypeScript-based front-end applications.
⚠️ Warning This package is currently in beta and may have breaking changes. Use with caution in production environments.
- 🚀 Generate API route definitions with TypeScript types
- 🔗 Generate URL helpers for clean and structured navigation
- ⚡ Inertia.js form helpers for better integration with Laravel-Inertia apps
- 🔥 Automatic TypeScript typing for request parameters
TypoWay utilizes the dedoc/scramble
package to analyze Laravel routes and extract type definitions.
Install the package via Composer:
composer require emhashef/typoway --dev
Run the command to generate TypeScript route files:
php artisan typoway:generate
--apis
→ Generate API routes only--inertia
→ Generate Inertia.js routes only
Example:
php artisan typoway:generate --apis
Running the command generates the following TypeScript files:
routes.ts
– Contains all routes, APIs, and Inertia form helpers.routes.urls.setup.ts
– Handles URL generation.routes.apis.setup.ts
– Handles API request methods.routes.inertia.setup.ts
– Handles Inertia form handling.
Example Output:
export const urls = {
test: {
index: () => `/api/test`,
storeArray: () => `/api/store-array`,
},
};
export const apis = {
test: {
index: (data?: { name?: string }): ApiResponse<{ name?: string }> =>
request("get", urls.test.index(), data),
storeArray: (data?: { bob?: number[] }): ApiResponse<any> =>
request("post", urls.test.storeArray(), data),
},
};
To publish the configuration file, run the following command:
php artisan vendor:publish --tag=typoway
You can configure excluded route names in the config/typoway.php file. These routes will not be included in the generated TypeScript definitions.
return [
'except-routes' => [
"filament*",
"scramble*",
"debugbar*",
"dusk*",
"ignition*",
"livewire*",
]
];
Modify this array to exclude additional route names as needed. Wildcards (*) can be used to match multiple routes.
This package is open-source and released under the MIT License.