TypeScript and Glint
inertia-ember is written in TypeScript and ships its types. Glint checks .gts templates against them, the way tsc checks TSX and vue-tsc checks single-file components. Use ember-tsc --noEmit where you'd use tsc.
Shared props, flash data and errors
The same InertiaConfig the React, Vue and Svelte adapters read types the shared props, the flash data and the error values everywhere: @props, page, usePage(), useForm and <Form>.
// resources/js/types.ts
declare module '@inertiajs/core' {
export interface InertiaConfig {
sharedPageProps: { auth: { user: User | null } };
flashDataType: { toast?: string };
errorValueType: string;
}
}The demo's, with the types of the props its Rust handlers send:
// The shapes the Rust handlers send. `Timestamp`s arrive as strings.
export interface Idea {
id: number;
title: string;
body: string;
category: string;
votes: number;
created_at: string;
updated_at: string;
}
export interface Comment {
id: number;
idea_id: number;
author: string;
body: string;
created_at: string;
updated_at: string;
}
/** What the idea forms send (IdeaInput on the server). */
export interface IdeaInput {
title: string;
category: string;
body: string;
}
/** `inertia::scroll_with(...)` of a paginator. */
export interface Paginated<T> {
data: T[];
current_page: number;
last_page: number;
per_page: number;
total: number;
}
// Props every page gets (HandleInertiaRequests::share) and the flash data, for `@props`, `page` and `usePage()`.
declare module '@inertiajs/core' {
export interface InertiaConfig {
sharedPageProps: {
appName: string;
laravelVersion: string;
status: string | null;
};
flashDataType: {
toast?: string;
};
errorValueType: string;
}
}Page props
PageSignature<Props> gives a page its @props: yours, the shared ones and errors. Glint checks the template against it, so {{@props.idea.titel}} is an error. LayoutSignature does the same for layouts.
interface Props {
idea: Idea;
similar?: Idea[]; // deferred: undefined until it arrives
}
export default class Show extends Component<PageSignature<Props>> {
form = useForm({ title: this.args.props.idea.title }); // form.title: string, form.errors.title
<template>…</template>
}Forms
useForm<T> and useHttp<T, Response> are generic over their fields, dot paths included: form.set('address.city', …) is checked. createForm<T>() gives a <Form> whose block knows its field names.
Signatures
Every component and modifier exports its Glint signature (LinkSignature, FormSignature, BindSignature, …), for wrapping them in your own components. head-key is a known attribute.