---
title: types generate
description: Generates TypeScript type definitions (.d.ts files) for Storyblok components that have been generated with the components pull command.
url: https://www.storyblok.com/docs/tooling/cli/types-generate
---

# types generate

Generates TypeScript type definitions (`.d.ts` files) for Storyblok components that have been generated with the `components pull` command. `types generate` must include any flags used when running `components pull` to ensure components are matched correctly.

By default, the command generates two files:

-   `.storyblok/types/storyblok.d.ts`: Base Storyblok types
-   `.storyblok/types/<space-id>/storyblok-component.d.ts`: Space-specific component types

The command also creates types for any datasources that are referenced in the components’ schemas.

## Prerequisites

-   The command relies on the presence of component files generated by `components pull` to create accurate type definitions.

## Usage

```bash
types generate [flags]
```

## Flags

| Flag | Type | Description |
| --- | --- | --- |
| `--space` | integer | _Required._ The ID of the Storyblok space to generate types for. |
| `--strict` | boolean | _Optional._ Enable strict mode for type generation, creating types that are more precise. |
| `--type-prefix` | string | _Optional._ Prepend a prefix to the generated types. |
| `--filename` | string | _Optional._ Specify a custom filename. Defaults to `storyblok-components.d.ts`. Ignored when `--separate-files` is used. |
| `--separate-files`, `-sf` | boolean | _Optional._ Save component type definitions as separate file, plus a `datasource-types.d.ts` containing all datasource type definitions as well as a `content-types.d.ts` containing all content type type definitions. |
| `--suffix` | string | _Optional._ Specify a custom suffix for type definition files. |
| `--path` | string | _Optional._ Specify a custom path for type definitions. Defaults to `.storyblok/types/<space-id>`. |
| `--compiler-options` | string | _Optional._ Specify a path to compiler options from `json-schema-to-typescript`. |
| `--custom-fields-parser` | string | _Optional._ Specify a path to a parser for custom field types. |

## Examples

The following examples assume that a `space` has been defined in a configuration file.

```bash
# Generate types for all components from a space
storyblok types generate
# Generate types for all components from a space with strict mode enabled
storyblok types generate --strict
# Generate types for all components from a space, reading each from a separate file with a custom suffix
storyblok types generate --separate-files --suffix dev
# Generate types for all components from a space, saving with a custom filename
storyblok types generate --filename my-types
```

## Pagination

-   [Previous: stories validate](/docs/tooling/cli/stories-validate)
-   [Next: user](/docs/tooling/cli/user)
