Inertia Typegen

TypeScript types and route helpers for Inertia pages, generated from your Laravel routes, controllers and form requests. You write no types by hand.

Visit inertia-typegen.vagebond.nl GitHub composer require vagebond/inertia-typegen
Made by
Vagebond
Type
Open source
Stack
PHP, Laravel, Inertia
A Laravel controller and a form request next to the TypeScript types that Inertia Typegen generates from them.

Page props

Each Inertia::render() call becomes a page type. A controller that renders posts/index gives Inertia.Pages.Posts.Index. Deferred props are optional.

public function index(): Response
{
    return Inertia::render('posts/index', [
        'posts' => PostResource::collection(Post::all()),
    ]);
}

Form requests

The rules of a form request become the type of its form data.

const form = useForm<Inertia.Requests.Posts.Store>({ title: '' })

Route helpers

Each named route gets a typed helper that builds its URL.

router.visit(show.url({ post: props.posts[0].id }))

Resources and paginators

JSON resources, resource collections and paginators keep their real shape, with typed data. A PHP enum becomes a union of its values.

Live in development, checked in CI

The Vite dev server generates the files again after a PHP change. In CI, inertia-typegen --check fails when the committed files are stale.

Stack

  • PHP
  • Laravel
  • Inertia
  • Scramble
  • TypeScript
  • Vite
  • Pest