Skip to content

Inertia TypegenTypeScript types for Inertia pages, from your Laravel code

Page props, form requests, shared data and route helpers, generated through Scramble. You write no types by hand.

From PHP to TypeScript ​

A controller and a form request:

php
public function login(): Response
{
    return Inertia::render('auth/login', [
        'canResetPassword' => true,
    ]);
}
php
public function rules(): array
{
    return [
        'title' => ['required', 'string'],
        'published' => ['boolean'],
    ];
}

The generator writes this to inertia.d.ts:

ts
export namespace Inertia {
  export namespace Pages {
    export namespace Auth {
      export type Login = Inertia.Shared.App & {
        canResetPassword: boolean
      }
    }
  }
  export namespace Requests {
    export namespace Posts {
      export type Store = {
        title: string
        published?: boolean
      }
    }
  }
}

A page then uses the types and the route helpers:

vue
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3'
import { store } from '@/routes/admin/posts'
import type { Inertia } from '@/types/inertia'

defineProps<Inertia.Pages.Posts.Create>()

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

form.post(store.url())
</script>

Read the introduction to see how it works.

Released under the MIT License.