Configure TypeScript for Ziggy
2.xZiggy provides TypeScript definitions and an Artisan command to generate autocompletion for route names and parameters.
1. Generate route types
Run the following command to generate type definitions:
php artisan ziggy:generate --types2. Make route() globally available
To allow your IDE to recognize the global route helper, add this to a .d.ts file:
import { route as routeFn } from 'ziggy-js';
declare global {
var route: typeof routeFn;
}3. Configure paths (if not using NPM)
If you haven't installed the ziggy-js NPM package, add the following to your tsconfig.json or jsconfig.json to load types from your vendor directory:
{
"compilerOptions": {
"paths": {
"ziggy-js": ["./vendor/tightenco/ziggy"]
}
}
}4. Enable strict route name checking
To trigger a type error when calling route() with an unrecognized route name, extend the TypeConfig interface:
declare module 'ziggy-js' {
interface TypeConfig {
strictRouteNames: true
}
}