Skip to content

defineCollection

defineCollection<TFieldMeta, TCollectionMeta, TCollectionSlug, TFields, TComponent, TDrafts, TTimestamps>(config): CollectionConfig<TFieldMeta & object, TCollectionMeta, TCollectionSlug, TFields, TComponent, TDrafts, TTimestamps, CollectionDataFieldSlug<TFields, TTimestamps>>

Defined in: packages/core/src/collections/config.ts:89

Resolves a raw collection config input into a fully-populated CollectionConfig.

Fills in any missing labels by deriving them from the slug — singularizing then title-casing it for singular, and title-casing the slug itself for plural (slugs are plural by convention).

TFieldMeta extends object = { }

TCollectionMeta extends object = { }

TCollectionSlug extends string = string

TFields extends Record<string, AdminField<TFieldMeta>> = Record<string, AdminField<TFieldMeta>>

TComponent extends ComponentHKT = ComponentHKT

TDrafts extends boolean = false

TTimestamps extends boolean = true

string extends keyof TFields ? CollectionConfigInput<TFieldMeta, TCollectionMeta, TCollectionSlug, TFields, TComponent, TDrafts, TTimestamps> : [keyof TFields & "vex_status" | "vex_publishedAt" | "vex_publishedId" | "vex_activeVersion" | "updatedAt"] extends [never] ? CollectionConfigInput<TFieldMeta, TCollectionMeta, TCollectionSlug, TFields, TComponent, TDrafts, TTimestamps> : object

The raw collection configuration supplied by the caller.

CollectionConfig<TFieldMeta & object, TCollectionMeta, TCollectionSlug, TFields, TComponent, TDrafts, TTimestamps, CollectionDataFieldSlug<TFields, TTimestamps>>

The resolved CollectionConfig with all defaults applied.

defineCollection({
slug: "posts",
fields: {
title: text({ required: true }),
},
});
// → { slug: "posts", admin: { useAsTitle: "_id" }, labels: { singular: "Post", plural: "Posts" }, fields: { ... } }