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
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):
// 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 asT | null(nullif that locale hasn't been translated yet). Non-localized fields are plain, non-nullable types, with two exceptions, both localized or not. AcontentTemplateblock isT | null(since@strifeapp/strife2.2.0). Every list (chapters,related,references,repeatable, labels, multipleselectand the other fields that read as an array) isT[] | 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 asnulltoo. A non-localized list stored empty reads as[]. Read a list aspage.sections ?? []. reference,references,chapters, andcontentTemplatefields resolve to the target type's own generated interface, not a raw identifier — areferenceto yourAuthortype producesauthor: Author[]rather than an opaque reference object.displayNameonContentis always astring, also on a type withbaseProperties: { displayName: { localizable: true } }— the content index resolves it to the requested locale, falling back to the default locale's name.basePropertieschanges nothing in the generated types (see LocalizabledisplayNameandslug).
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
npx strife typegen validate [--config <path>] [-o | --output <path>] [--allow-missing-ids]A CI-friendly check combining two things:
- Lint. Two schemas that resolve to the same
collectionis a hard failure, and so, from@strifeapp/cli0.1.20, is a deprecatedfields.reference()field when the project's@strifeapp/strifeis 2.0.0 or later, whichpushrefuses too. With an older@strifeapp/strife, both only warn about it. Areferencesorchaptersfield (referencebefore 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. Afrom: { id: process.env.X }entry whose variable is unset is a failure (the template would lose its parent rule silently), and so is afields.labels()field whosegroup: { id }variable is unset, which would offer every label;--allow-missing-idsdemotes both to warnings. A field stored under a name Strife reserves fails bothgenerateandvalidate, andvalidatewarns about a name the content index fills itself; see Don't shadow the built-inContentfields. Bothgenerateandvalidateload.env.localand.envfrom 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 inpush. - 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-rungenerate.
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 generateproduces local TypeScript types only. Nothing leaves your machine.pushdeploys your schema as templates to the linked team, plus the content index and (optionally) localization settings.
Neither command touches existing content documents.