Types
inertia-ember ships its types. With Glint (@glint/ember-tsc), templates in .gts files are checked against them: a page's @props, a component's arguments and blocks, a modifier's arguments. Run ember-tsc --noEmit where you'd run tsc.
import type { TOC } from '@ember/component/template-only';
import type { PageSignature } from 'inertia-ember';
interface Props {
product: { name: string; price: number };
}
export default <template>
<h1>{{@props.product.name}}</h1>
<p>{{@props.product.nmae}}</p>
{{! Glint: Property 'nmae' does not exist }}
</template> satisfies TOC<PageSignature<Props>>;PageSignature
A page component's signature: it gives the page its @props, typed as your props plus the shared props and errors.
Signature
interface PageSignature<TProps extends object = Record<string, unknown>> {
Args: { props: PagePropsOf<TProps> };
}Examples
A class page
import Component from '@glimmer/component';
import type { PageSignature } from 'inertia-ember';
interface Props {
invoice: { number: string; total: number };
payments?: { id: number; amount: number }[]; // deferred: undefined until it arrives
}
export default class Show extends Component<PageSignature<Props>> {
get paid() {
return (this.args.props.payments ?? []).reduce((sum, payment) => sum + payment.amount, 0);
}
<template>
<h1>Invoice {{@props.invoice.number}}</h1>
<p>{{this.paid}} of {{@props.invoice.total}} paid</p>
</template>
}A template-only page
import type { TOC } from '@ember/component/template-only';
import type { PageSignature } from 'inertia-ember';
export default <template>
<h1>{{@props.title}}</h1>
</template> satisfies TOC<PageSignature<{ title: string }>>;Mark props the server sends later (deferred, lazy, on visibility) as optional, so the types say they can be missing.
LayoutSignature
A persistent layout's signature: the page's props as @props, the layout's @name when it's one of a page's named layouts, and a default block for the page.
Signature
interface LayoutSignature<TProps extends object = Record<string, unknown>> {
Args: { props: PagePropsOf<TProps>; name?: string | undefined };
Blocks: { default: [] };
}TProps is what the layout reads beyond the shared props: usually the props pages hand it with setLayoutProps, as optional keys.
Examples
import Component from '@glimmer/component';
import { type LayoutSignature, Link } from 'inertia-ember';
export default class AppLayout extends Component<LayoutSignature<{ title?: string }>> {
<template>
<nav>
<Link @href='/'>Home</Link>
{{#if @props.auth.user}}{{@props.auth.user.name}}{{/if}}
</nav>
<h1>{{@props.title}}</h1>
<main>{{yield}}</main>
</template>
}PagePropsOf
The props a page gets: yours, the shared props from your InertiaConfig, and errors. Unlike Page['props'] it has no catch-all key, so reading a prop the page doesn't have is a type error. PageSignature, LayoutSignature and usePage() use it.
Signature
type PagePropsOf<TProps extends object = Record<string, unknown>> = SharedPageProps &
TProps & {
errors: Errors & ErrorBag;
};Examples
Type a function that takes a page's props
import type { PagePropsOf } from 'inertia-ember';
type Props = PagePropsOf<{ cart: { items: { price: number }[] } }>;
export const cartTotal = (props: Props) => props.cart.items.reduce((sum, item) => sum + item.price, 0);SharedPageProps and InertiaConfig
SharedPageProps is the type of the props every page gets (the ones the server shares on every response). It comes from @inertiajs/core's InertiaConfig, the same interface the React, Vue and Svelte adapters read. Declare it once:
// types.ts (any file the type checker includes)
declare module '@inertiajs/core' {
export interface InertiaConfig {
sharedPageProps: { auth: { user: { id: number; name: string } | null } };
flashDataType: { toast?: string };
errorValueType: string;
layoutProps: { title: string };
namedLayoutProps: { sidebar: { collapsed: boolean } };
}
}| Key | Types | Default |
|---|---|---|
sharedPageProps | SharedPageProps: @props in every page and layout, page.props, usePage().props | PageProps (any key) |
flashDataType | page.flash | { [key: string]: unknown } |
errorValueType | each value in errors, form.errors, <Form>'s errors | string |
layoutProps | what setLayoutProps(props) takes | Record<string, unknown> |
namedLayoutProps | the names and props setLayoutProps(name, props) takes | Record<string, Record<string, unknown>> |
With it declared:
import { page } from 'inertia-ember';
page.props.auth.user?.name; // string | undefined
page.flash.toast; // string | undefined
page.props.auth.team; // type error: not a shared propComponent and modifier signatures
Every component and modifier exports its Glint signature, for wrapping it in a component of your own. Each one's Element is where ...attributes goes, Args are its @arguments, and Blocks what it yields.
| Type | For | Element | Blocks |
|---|---|---|---|
LinkSignature | <Link> | HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement | default |
HeadSignature | <Head> | none | default |
DeferredSignature | <Deferred> | none | default and rescue ({ reloading }), fallback |
WhenVisibleSignature | <WhenVisible> | HTMLElement | default ({ fetching }), fallback |
WhenMountedSignature | <WhenMounted> | none | default, fallback |
InfiniteScrollSignature | <InfiniteScroll> | HTMLElement | default, previous, next, loading |
FormSignature<TForm> | <Form> | HTMLFormElement | default (FormApi<TForm>) |
InertiaAppSignature | App | none | none |
BindSignature | {{bind}} | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | positional [form, field], named validate |
InertiaSignature | {{inertia}} | HTMLElement | named: LinkOptions |
head-key is declared as a known HTML attribute, so <meta head-key='description'> checks.
Examples
Wrap <Link> in a component of your own
import type { TOC } from '@ember/component/template-only';
import { Link, type LinkSignature } from 'inertia-ember';
interface NavLinkSignature {
Element: LinkSignature['Element'];
Args: { href: LinkSignature['Args']['href']; prefetch?: LinkSignature['Args']['prefetch'] };
Blocks: LinkSignature['Blocks'];
}
const NavLink: TOC<NavLinkSignature> = <template>
<Link @href={{@href}} @prefetch={{if @prefetch @prefetch 'hover'}} class='nav-link' ...attributes>
{{yield}}
</Link>
</template>;
export default NavLink;A typed <Form>
createForm<T>() returns <Form> typed by its fields, so form.errors.title checks and form.errors.titel doesn't:
import { createForm } from 'inertia-ember';
const PostForm = createForm<{ title: string; body: string }>();
<template>
<PostForm @action='/posts' @method='post' as |form|>
<input name='title' />
{{#if form.errors.title}}<p>{{form.errors.title}}</p>{{/if}}
</PostForm>
</template>Other exported types
| Type | What it is | See |
|---|---|---|
Page, PageProps | A page as the server sends it, and its props with a catch-all key. From @inertiajs/core. | page |
Method | 'get' | 'post' | 'put' | 'patch' | 'delete' | 'query'. From @inertiajs/core. | router |
UrlMethodPair | { url, method, component? }, what typed route helpers return; router, <Link> and forms take it as a URL. From @inertiajs/core. | router |
FormDataConvertible | A value that can go in a request: strings, numbers, booleans, files, dates, arrays and objects of them. From @inertiajs/core. | useForm |
CreateInertiaAppOptions, AppOwner, PageRenderer | createInertiaApp's options, the owner it takes, and what it resolves to on the server. | Setup |
PageComponent, ResolvedPage | A page or layout component (@props, @name, a default block), and what resolve may return. | Setup |
InertiaOwner, CreateOwnerOptions, Modules, ServiceEntry | The lightweight @ember/owner createOwner resolves to, and the module map or { services } options it takes. | createOwner |
Poll, Prefetch, Prop | What usePoll, usePrefetch and useProp return. | Hooks |
UseForm, FormSubmitOptions | A useForm form (InertiaForm<T> & T), and the options of its submit methods. | useForm |
UseHttp, HttpSubmitOptions, HttpOptimisticCallback | A useHttp client, its request options, and its optimistic callback. | useHttp |
FormField, FormDataShape, OptimisticCallback | A field name or dot path of a form, the default shape of form data, and a form's optimistic callback. | useForm |
FormApi | What <Form> yields and useFormContext returns. | <Form> |
LinkOptions | The arguments <Link> and {{inertia}} share. | <Link> |
Related: TypeScript and Glint, Pages and layouts, page, Setup, API overview.