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
Section titled “Prerequisites”- The command relies on the presence of component files generated by
components pullto create accurate type definitions.
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. |
Examples
Section titled “Examples”The following examples assume that a space has been defined in a configuration file.
# Generate types for all components from a spacestoryblok types generate# Generate types for all components from a space with strict mode enabledstoryblok types generate --strict# Generate types for all components from a space, reading each from a separate file with a custom suffixstoryblok types generate --separate-files --suffix dev# Generate types for all components from a space, saving with a custom filenamestoryblok types generate --filename my-typesWas this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.
Get in touch with the Storyblok community