Menu

From Inertia::render() to a page type
📰

From Inertia::render() to a page type

DEV Community: laravel·Vagebond·1 day ago
#qr3Nmy77
#devtolaravel#devto#dev#type#inertia
Reading 0:00
15s threshold

You type your Inertia props by hand. Then a controller changes, and the types drift.

Inertia Typegen generates TypeScript types and route helpers for Inertia pages. It reads them from Scramble's OpenAPI document. You write no types by hand.

This post walks from the PHP input to the TypeScript output.

Install

composer require vagebond/inertia-typegen composer require --dev dedoc/scramble

Enter fullscreen mode

Exit fullscreen mode

Scramble is a development dependency. Inertia Typegen requires PHP 8.3+, Laravel 12 or 13, and Scramble 0.13.49+. It also needs inertia-laravel 2 or 3, Node 22.18+ and Vite 6+.

The PHP input

Here is a controller with an enum and a paginated resource collection.

enum PostStatus : string { case Draft = 'draft' ; case Published = 'published' ; }

class PostController { public function index () { return Inertia :: render ( 'Posts/Index' , [ 'posts' => PostResource :: collection ( Post :: paginate ()), 'status' => PostStatus :: Draft , ]); } }

Enter fullscreen mode

Exit…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.