Skip to content

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.

gts
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 ​

ts
interface PageSignature<TProps extends object = Record<string, unknown>> {
  Args: { props: PagePropsOf<TProps> };
}

Examples ​

A class page ​

gts
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 ​

gts
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 ​

ts
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 ​

gts
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 ​

ts
type PagePropsOf<TProps extends object = Record<string, unknown>> = SharedPageProps &
  TProps & {
    errors: Errors & ErrorBag;
  };

Examples ​

Type a function that takes a page's props ​

ts
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:

ts
// 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 } };
  }
}
KeyTypesDefault
sharedPagePropsSharedPageProps: @props in every page and layout, page.props, usePage().propsPageProps (any key)
flashDataTypepage.flash{ [key: string]: unknown }
errorValueTypeeach value in errors, form.errors, <Form>'s errorsstring
layoutPropswhat setLayoutProps(props) takesRecord<string, unknown>
namedLayoutPropsthe names and props setLayoutProps(name, props) takesRecord<string, Record<string, unknown>>

With it declared:

ts
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 prop

Component 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.

TypeForElementBlocks
LinkSignature<Link>HTMLAnchorElement | HTMLButtonElement | HTMLSpanElementdefault
HeadSignature<Head>nonedefault
DeferredSignature<Deferred>nonedefault and rescue ({ reloading }), fallback
WhenVisibleSignature<WhenVisible>HTMLElementdefault ({ fetching }), fallback
WhenMountedSignature<WhenMounted>nonedefault, fallback
InfiniteScrollSignature<InfiniteScroll>HTMLElementdefault, previous, next, loading
FormSignature<TForm><Form>HTMLFormElementdefault (FormApi<TForm>)
InertiaAppSignatureAppnonenone
BindSignature{{bind}}HTMLInputElement | HTMLSelectElement | HTMLTextAreaElementpositional [form, field], named validate
InertiaSignature{{inertia}}HTMLElementnamed: LinkOptions

head-key is declared as a known HTML attribute, so <meta head-key='description'> checks.

Examples ​

gts
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:

gts
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 ​

TypeWhat it isSee
Page, PagePropsA 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
FormDataConvertibleA value that can go in a request: strings, numbers, booleans, files, dates, arrays and objects of them. From @inertiajs/core.useForm
CreateInertiaAppOptions, AppOwner, PageRenderercreateInertiaApp's options, the owner it takes, and what it resolves to on the server.Setup
PageComponent, ResolvedPageA page or layout component (@props, @name, a default block), and what resolve may return.Setup
InertiaOwner, CreateOwnerOptions, Modules, ServiceEntryThe lightweight @ember/owner createOwner resolves to, and the module map or { services } options it takes.createOwner
Poll, Prefetch, PropWhat usePoll, usePrefetch and useProp return.Hooks
UseForm, FormSubmitOptionsA useForm form (InertiaForm<T> & T), and the options of its submit methods.useForm
UseHttp, HttpSubmitOptions, HttpOptimisticCallbackA useHttp client, its request options, and its optimistic callback.useHttp
FormField, FormDataShape, OptimisticCallbackA field name or dot path of a form, the default shape of form data, and a form's optimistic callback.useForm
FormApiWhat <Form> yields and useFormContext returns.<Form>
LinkOptionsThe arguments <Link> and {{inertia}} share.<Link>

Related: TypeScript and Glint, Pages and layouts, page, Setup, API overview.

Released under the MIT License.