Skip to content

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.

  • The command relies on the presence of component files generated by components pull to create accurate type definitions.
Terminal window
types generate [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.

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

Terminal window
# 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

Was this page helpful?

What went wrong?

This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.