Skip to content

generateVexTypes

generateVexTypes(props): string

Defined in: packages/core/src/types/generateVexTypes.ts:84

Generates the full contents of vex.types.ts from a resolved VexConfig.

When there are no collections, returns only the auto-generated header. When collections are present, the output contains:

  • Imports for Id (from @convex/_generated/dataModel) and VexDocument (from @vexcms/core)
  • One export interface per collection, extending VexDocument with a branded Id<"slug"> for _id
  • export type CollectionSlug — union of all collection slugs
  • export type DocumentBySlug — map of slug to document interface
  • declare module '@vexcms/core' block that augments GeneratedVexTypes, narrowing CollectionSlug and DocumentBySlug inside @vexcms/core itself

Input props.

VexConfig

The fully resolved Vex configuration.

string

The complete TypeScript source string to write to vex.types.ts.

const config = defineConfig({
collections: [
defineCollection({ slug: "posts", fields: { title: text({ required: true }) } }),
],
});
const contents = generateVexTypes({ config });
// Writes to vex.types.ts:
// import type { Id } from "@convex/_generated/dataModel"
// import type { VexDocument } from "@vexcms/core"
// export interface PostsDocument extends VexDocument { _id: Id<"posts">; title: string }
// export type CollectionSlug = "posts"
// export type DocumentBySlug = { posts: PostsDocument }
// declare module "@vexcms/core" { interface GeneratedVexTypes { ... } }