Skip to content

collectionConfigToFieldTypeMap

collectionConfigToFieldTypeMap(props): string

Defined in: packages/core/src/collections/interfaceGen.ts:119

Converts a resolved CollectionConfig to the TypeScript source string for its CollectionsFieldTypeMap entry used in the declare module '@vexcms/core' block.

The output maps each field type present in the collection to a union of that collection’s field keys of that type, plus a fixed id: "_id" entry. This lets framework code look up field keys by type at the TypeScript level — for example, finding all text fields on a given collection for search.

Input props.

CollectionConfig

The resolved collection definition to convert.

string

A TypeScript source string for one CollectionsFieldTypeMap entry (without wrapping braces).

const posts = defineCollection({
slug: "posts",
fields: { title: text({ required: true }), author: relationship({ collection: { slug: "authors" } }) },
});
collectionConfigToFieldTypeMap({ collection: posts });
// → '\tposts: {\n\t\tid: "_id"\n\t\ttext: "title"\n\t\trelationship: "author"\n\t}'

generateVexTypes for the full-file generator that wraps this function