> From the [Strife developer docs](https://strife.app/docs/reference/typescript). Every page is listed in [llms.txt](https://strife.app/docs/llms.txt).

# TypeScript

TypeScript types for Strife content from the @strifeapp/types package: Content, the shape of every row in the content index, and the value types that fields return.

`@strifeapp/types` has the TypeScript types for Strife content: the shape of every row in the content index, and the value types that fields return.

```bash
npm install @strifeapp/types
```

## Content

`Content` is the shape of a row in the content index, [`Content/ByUrl`](https://strife.app/docs/reference/database/index-url.md), with one row per page and language. Your templates' types extend it.

| Field | Type | What it holds |
| --- | --- | --- |
| `id` | `string` | The row's document id. |
| `docId` | `string` | The page's document id. For published content it is the same as `id`. |
| `locale` | `string` | The language of the row. |
| `displayName` | `string` | The page's name in Studio. |
| `url` | `string \| null` | The page's address, or `null` when the template has no addresses. |
| `origin` | `string \| null` | The id of the page it sits under, or `null` at the top. |
| `collection` | `string` | The template's collection. |
| `draft` | `boolean` | `true` on draft and working-copy rows. Read with `selectFields`, it comes back as the text `"true"` or `"false"`, so filter on `status` instead; see [Index URL](https://strife.app/docs/reference/database/index-url.md). |
| `publishedAt` | `string \| null` | When the page was published, as an ISO 8601 string. |
| `createdAt` | `string` | When the page was created, as an ISO 8601 string. |
| `changedAt` | `string` | When the page last changed, as an ISO 8601 string. |
| `dependencies` | `string[]` | The ids of the documents set as the page's dependencies. |
| `labels` | `string[]` | The page's labels by name, as `group/label` for a label in a group. See [Label Groups](https://strife.app/docs/reference/database/label-groups.md). |

## Types for your templates

Let `strife typegen generate` write them. It reads your schemas and writes one interface per template, each extending `Content`, to `.strife/types.ts`:

```ts
// AUTO-GENERATED by `strife typegen generate`
import type { Content } from '@strifeapp/types';

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

See [Typegen](https://strife.app/docs/reference/cli/typegen.md). Without the CLI, extend `Content` yourself with the value types below:

```ts
import type { Content, Image, Link } from '@strifeapp/types';

interface Article extends Content {
  heading: string;
  image: Image;
  readMore: Link;
}
```

## Value types

| Type | Shape | Returned by |
| --- | --- | --- |
| `Image` | `{ width, height, source, alt }`, where `source` is an `ImageSource` with the URL of the generated file and, for a field with `widths`, a ready `srcset` | an image field |
| `ImageGroup` | One `Image` per screen size, keyed by the size's name | an image group field |
| `Link` | `{ href, target, id?, text? }`, where `id` is set for links to pages in Strife | a link field |
| `FileValue` | `{ name, size, type, extension, src, draft }` | a file field |
| `Serp` | `{ title, keywords, description }` | the SEO field |
| `ComboBoxValue` | `{ value, name }`. A select field returns an array of them, even with one choice. | a select field |
| `ContentReference` | `{ id, displayName }` | a related document |
| `Label`, `LabelGroup` | A label and a label group, as Studio stores them | the team's labels |
| `Chapter`, `Asset`, `CollectionDefinition`, `CollectionType`, `OriginReference`, `SourceSet`, `Template` | Building blocks for chapters, asset lists, collections, origins, image sources and templates | |

The package also exports the types for saving content through Strife's API.
