Type generation

Learn how the CLI generates type definitions for your project.

The CLI generates type definitions for your project based on your slot and component schemas. These definitions give your editor autocomplete and type checking when working with content.

How it works

Every time you add, remove, install, update, or upgrade slots or components, the CLI fetches the corresponding schemas from your workspace and generates type definitions for the SDK in use.

Which versions get types depends on the version specifier set for each entry in the configuration file.

For example, in TypeScript projects this produces a slots.d.ts file that the CLI automatically registers in tsconfig.json. This means calls like fetchContent('home-hero@2') return the correct content type without any manual type annotations.

Slots vs. components

Both slots and components get type definitions, but they serve different purposes.

Slot types define the content structure you receive when fetching content. They determine the shape of the object returned by functions like fetchContent or hooks like useContent, so your code knows exactly which properties are available.

Component types define reusable content structures that can appear inside slots. Because multiple slots can reference the same component, having a dedicated type for it lets you write shared rendering logic once and reuse it across different slots.

For example, in TypeScript projects, the generated types let you write code like this:

import type {SlotContent, ComponentContent} from '@croct/plug-next';
// Type the full content of a slottype HeroContent = SlotContent<'home-hero@1'>;
// Type a reusable component shared across slotstype CardProps = ComponentContent<'card@1'>;
function Card(props: CardProps) {  return <div>{props.title}</div>;}

Synchronization

The install command regenerates all type definitions. The CLI registers a postinstall hook so types stay in sync automatically whenever dependencies are installed.

You can also run update to re-fetch schemas and regenerate types without changing any version specifiers. If you want to move to a newer major version, use upgrade instead, which updates the version specifiers in the configuration file and then regenerates types accordingly.

Version control

The generated type definitions file does not need to be committed since the CLI regenerates it on install. However, committing it is recommended to avoid fetching definitions from the API at build time.