Skip to content
Strife Docs

Tools CLI

Typegen

Generate TypeScript types from your defineType schemas, and keep them in sync with a CI check.

strife typegen turns your schema definitions into TypeScript types matching what the content API actually returns — useful whether or not the rest of your project uses TypeScript. Both subcommands are fully offline: no network request, no authentication, no linked project required. They only need a strife.config.ts and your schema files.

strife typegen generate

Terminal
npx strife typegen generate [--config <path>] [-o | --output <path>]

Reads your schema files and writes TypeScript interfaces to .strife/types.ts (override the path with -o/--output):

TypeScript
// AUTO-GENERATED by `strife typegen generate` — do not edit by hand.

import type { Content } from '@strifeapp/types';

export interface Articles extends Content {
  heading: string | null;
  body: string;
}

The generated shape is the read shape — what you get back after fetching a document, not the raw stored form. Two things follow from that:

  • Localized fields (localizable: true) collapse to the active locale as T | null (null if that locale hasn't been translated yet). Non-localized fields are plain, non-nullable types, with two exceptions, both localized or not. A contentTemplate block is T | null (since @strifeapp/strife 2.2.0). Every list (chapters, related, references, repeatable, labels, multiple select and the other fields that read as an array) is T[] | null (chapters since 2.2.0, the others since 2.3.0). A document created before the field existed, or through the API without it, has no value for it. A list that comes out empty for the locale you read, for example one that has no entries in that language or whose pages are all unpublished, reads as null too. A non-localized list stored empty reads as []. Read a list as page.sections ?? [].
  • reference, references, chapters, and contentTemplate fields resolve to the target type's own generated interface, not a raw identifier — a reference to your Author type produces author: Author[] rather than an opaque reference object.
  • displayName on Content is always a string, also on a type with baseProperties: { displayName: { localizable: true } } — the content index resolves it to the requested locale, falling back to the default locale's name. baseProperties changes nothing in the generated types (see Localizable displayName and slug).

This is deliberately different from the type you'd get by statically inspecting a defineType() call's own shape (which describes what you write into the schema, not what you read back from the content API) — the generated types are the ones to build your frontend against.

strife typegen validate

Terminal
npx strife typegen validate [--config <path>] [-o | --output <path>] [--allow-missing-ids]

A CI-friendly check combining two things:

  1. Lint. Two schemas that resolve to the same collection is a hard failure, and so, from @strifeapp/cli 0.1.20, is a deprecated fields.reference() field when the project's @strifeapp/strife is 2.0.0 or later, which push refuses too. With an older @strifeapp/strife, both only warn about it. A references or chapters field (reference before 0.1.20) whose target doesn't match any locally-defined type is a warning, not a failure: the target might be defined elsewhere, e.g. pushed from another project. A from: { id: process.env.X } entry whose variable is unset is a failure (the template would lose its parent rule silently), and so is a fields.labels() field whose group: { id } variable is unset, which would offer every label; --allow-missing-ids demotes both to warnings. A field stored under a name Strife reserves fails both generate and validate, and validate warns about a name the content index fills itself; see Don't shadow the built-in Content fields. Both generate and validate load .env.local and .env from the current directory before reading the schemas: in a directory linked to a team, with that team's prefixed lines standing in for the plain names, as in push.
  2. Drift. Regenerates the types in memory and compares them byte-for-byte against the file on disk at --output. A missing file or any difference fails the check with a pointer to re-run generate.

Typical usage is running validate in CI after generate has been run and committed, to catch schema changes that weren't followed by a regenerated types file. A CI checkout is usually not linked to a team (strife link keeps .strife/ out of git), so no team-prefixed line applies there unless you commit .strife/project.json: set the plain variables that from: { id } and group: { id } read in the CI environment, or pass --allow-missing-ids.

Relationship to push

typegen and push both start from the same schema files but serve different purposes, and it's easy to conflate them:

  • typegen generate produces local TypeScript types only. Nothing leaves your machine.
  • push deploys your schema as templates to the linked team, plus the content index and (optionally) localization settings.

Neither command touches existing content documents.