Page props
Each Inertia::render() call becomes a page type. Deferred props are optional.
Page props, form requests, shared data and route helpers, generated through Scramble. You write no types by hand.
A controller and a form request:
public function login(): Response
{
return Inertia::render('auth/login', [
'canResetPassword' => true,
]);
}public function rules(): array
{
return [
'title' => ['required', 'string'],
'published' => ['boolean'],
];
}The generator writes this to inertia.d.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:
<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.