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.typesstill works as an alias, so existing scripts keep running.
Options
| Flag | Default | Description |
|---|---|---|
-p, --path <path> | .localess/localess.d.ts | Path to write the generated TypeScript definitions file |
--prefix <prefix> | (empty) | Prefix to prepend to all generated type names |
-v, --verbose | false | Print 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 CmsWhat gets generated
A single declaration file containing:
- Helper interfaces for the reference field kinds —
ContentAsset,ContentLink,ContentReference,ContentRichText - One
interfaceperROOTandNODEschema, each with_id: stringand a literal_schemamatching its schema id. Fields are optional unless marked required in the schema - One string-literal union per
ENUMschema - A
ContentDataunion of everyROOTtype
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 PageThe 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.