Localess

Types

Generate TypeScript type definitions from your Localess content schemas.

Fetch your space's content schemas directly from the Localess API and generate TypeScript type definitions from them. The output file provides full type safety when working with Localess content in your TypeScript projects.

Schemas are read live from the database — there is no intermediate OpenAPI document — so the generated types always reflect the current state of your space.

localess type generate [--path <output_path>]

The command group is type. types still works as an alias, so existing scripts keep running.

Options

FlagDefaultDescription
-p, --path <path>.localess/localess.d.tsPath to write the generated TypeScript definitions file
--prefix <prefix>(empty)Prefix to prepend to all generated type names
-v, --verbosefalsePrint verbose debug output

Your API token must have Development Tools permission enabled in Localess Space settings.

Examples

# Generate types to the default location
localess type generate

# Generate types to a custom path
localess type generate --path src/types/localess.d.ts

# Generate types with a prefix on all type names
localess type generate --prefix Cms

What gets generated

A single declaration file containing:

  • Helper interfaces for the reference field kinds — ContentAsset, ContentLink, ContentReference, ContentRichText
  • One interface per ROOT and NODE schema, each with _id: string and a literal _schema matching its schema id. Fields are optional unless marked required in the schema
  • One string-literal union per ENUM schema
  • A ContentData union of every ROOT type

Using Generated Types

import type { Page, HeroBlock } from './.localess/localess';
import { getLocalessClient } from "@localess/react";

const client = getLocalessClient();
const content = await client.getContentBySlug<Page>('home', { locale: 'en' });
// content.data is now fully typed as Page

The import path drops the .d.ts extension — TypeScript resolves ./.localess/localess to the generated declaration file.

Generating types vs. defining schemas in code

type generate is a one-way read: the CMS is the source of truth and your types follow it. If you'd rather define schemas in TypeScript and push them to the space, see Schema — the two approaches solve opposite directions of the same problem, and you'd normally pick one.

On this page