matter.work
Building Apps / The SDK

Typed tables

Generate TypeScript definitions from matter.json so every query, index, and field is checked at compile time.

matter app types generates matter-app.d.ts (or the path set in types inside matter.json) and augments the Tables, Boards, ModelSlots, Tools and Views interfaces of @matter.work/app-sdk. Include the generated file in your tsconfig.json so TypeScript checks every table, index, and field at compile time, and every tool a page calls.

What TypeScript checks for you#

With matter-app.d.ts included, matter.table('deals') is strictly typed and the compiler catches anything the Data API would reject at runtime:

  • Referencing a table, index, or field key that doesn’t exist.
  • Passing an eq filter that omits one of the index’s match fields or uses an unknown select option key.
  • Using range on a field other than the index’s first order field.
  • Passing unsupported sort or filter properties.
  • Calling groupCount with a by field that isn’t in the index’s match list.
  • Calling upsert on an index that isn’t marked unique: true.
  • Writing the wrong value type (or passing multiple people to a single-person field).

Returned rows are typed automatically: row.values.stage narrows to 'lead' | 'won' | 'lost' | (string & {}) (allowing for options another version of the app declares, while writes and eq strictly require declared option keys).

Typed Boards#

The same file types the boards your matter.json declares, by key: each board’s field values as reads return them, the input writes take, and its status keys.

matter-app.d.ts (excerpt)
interface Boards {
  /** Prospects */ pipeline: {
    values: { campaign?: LinkedRow; tier?: 'a' | 'b' | (string & {}); next_at?: DateString }
    input: { campaign?: RowRef | readonly [RowRef] | null; tier?: 'a' | 'b' | null; next_at?: DateString | null }
    status: 'new' | 'contacted' | 'meeting' | 'lost'
  }
}

matter.board('pipeline') then checks status keys in eq and writes, and field keys and values, and returns typed Tasks. Other boards of the space, named by name or ID, are untyped. See Boards and tasks.

Typed Paths#

List your app’s own routes in matter.json’s routes, and the same file types its paths: matter.panels.open, openTab, notify and search results then take only those, plus the paths your manifest names (pages, views, widgets, commands, setup). A :name segment matches any text, and a query string or hash may follow any path. Without routes, paths stay strings.

matter.json
"routes": ["/deals/:id", "/deals/:id/notes"]
src/deals.ts
await matter.panels.open(`/deals/${deal.id}`) // checked
await matter.panels.open('/dael/1') // a type error

// For your own links: AppPath is the same type.
import type { AppPath } from '@matter.work/app-sdk'
const href: AppPath = `/deals/${deal.id}/notes`

Keeping types in sync#

  • Regenerating types: Run matter app types whenever your table or board declarations in matter.json change.
  • Checked on deploy: matter app deploy warns you if your generated types file is out of date.
  • Manual command: Run matter app types at any time to regenerate the file directly from matter.json (no deploy required first).

Exported helper types#

@matter.work/app-sdk exports utility types for building your own typed wrappers and UI hooks:

Type Purpose
Tables Map of your app’s tables keyed by table key.
TableRead<T> Any valid query / watch read object for table T (enforcing each index’s match and range fields).
TableMatch<T> Any valid index match object for count, exists, and ids.
TableGroupRead<T> & TypedGroups<T, I> Input and return types for groupCount on table T and index I.
Row<Values> Typed row record with id, title, values, createdBy, createdAt, updatedAt, and cursor.
Boards & Board<B> Map of your app’s boards keyed by board key, and the handle matter.board returns for one.
Task<Values, Status> & TaskInput<Input, Status> A task as reads return it, and as writes take it.
BoardRead<Status> Any valid query / count / watch read of a board.
ModelSlots & ModelSlot Your app’s model slots, so the slot of a model call or a routine made in code is checked.
Person, LinkedRow, Attachment Value shapes for person, relation, and attachment fields.
Typing a query constant
import type { TableRead, Tables } from '@matter.work/app-sdk'

const OPEN_LEADS: TableRead<Tables['deals']> = {
  index: 'by_stage',
  eq: { stage: 'lead' },
  range: { field: 'value', gt: 1000 },
}