---
title: "Typegen types"
description: "Types for source type generation and the typegen:field plugin hook."
canonical_url: "https://content.comark.dev/reference/types/typegen"
---
# Typegen types

> Types for source type generation and the typegen:field plugin hook.

Types used by [`generateSourceTypes()`](https://content.comark.dev/guide/typescript) / [`writeSourceTypes()`](https://content.comark.dev/guide/typescript) and the [`typegen:field`](https://content.comark.dev/reference/content/hooks#typegenfield) hook.

```ts
import type {
  TypegenFieldContext,
  GenerateSourceTypesOptions,
  WriteSourceTypesOptions,
} from 'comark-content'
```

## `TypegenFieldContext`

Payload for the [`typegen:field`](https://content.comark.dev/reference/content/hooks#typegenfield) hook. Plugins mutate `type` in place and register imports through `imports`.

```ts
interface TypegenFieldContext {
  source: string
  path: string[]
  schema: JsonSchema
  layer: 'data' | 'row'
  type: string
  imports: TypegenImportCollector
}
```

| Field     | Description                                                                         |
| --------- | ----------------------------------------------------------------------------------- |
| `source`  | Source name being rendered.                                                         |
| `path`    | Field path inside the schema (for example `['items', 'answer']`).                   |
| `schema`  | JSON Schema node for this field.                                                    |
| `layer`   | `'data'` for `get()` shapes; `'row'` for flattened query columns.                   |
| `type`    | Mutable TS type string — starts as the default from JSON Schema.                    |
| `imports` | Call `imports.add('comark', 'MarkdownDocument')` to emit extra `import type` lines. |

See [`markdown-fields`](https://content.comark.dev/plugins/built-in/markdown-fields) for a complete example.

## `GenerateSourceTypesOptions`

Options passed to `generateSourceTypes(content, options?)`.

| Option       | Type      | Default            | Description                                                                         |
| ------------ | --------- | ------------------ | ----------------------------------------------------------------------------------- |
| `moduleName` | `string`  | `'comark-content'` | Module specifier augmented in the generated `declare module` block.                 |
| `paths`      | `boolean` | `true`             | Emit each instance's path map (path → data type). Pass `false` on very large sites. |

## `WriteSourceTypesOptions`

Extends `GenerateSourceTypesOptions` with output location options for `writeSourceTypes(content, options?)`.

| Option     | Type     | Default                 | Description                                     |
| ---------- | -------- | ----------------------- | ----------------------------------------------- |
| `outDir`   | `string` | `'.'`                   | Directory for the generated file.               |
| `fileName` | `string` | `'comark-content.d.ts'` | File name inside `outDir`.                      |
| `outFile`  | `string` | —                       | Explicit path; overrides `outDir` / `fileName`. |


## Sitemap

See the full [sitemap](https://content.comark.dev/sitemap.md) for all pages.
