I have a
ChatMessagescollection in a different file, and a
Profilecollection in a different one.
I have
ChatMessagesas
export const ChatMessages: CollectionConfig = {
slug: 'chat_messages',
fields: [
{
name: 'user',
type: 'relationship',
relationTo: 'profile',
required: false,
},
],
};Then I have
Profileas
export const Profile: CollectionConfig = {
slug: 'profile',
fields: [
...
],
};I export them as an array called 'collections', then I spread them into the
collectionsproperty of the buildConfig like so:
const collections = [Profile, ChatMessages];
buildConfig({ ..., collections: [...collections]})But when I try to compile with yarn build, I get
Type '"profile"' is not assignable to type 'CollectionSlug | CollectionSlug[]'., in reference to the
relationTofield in ChatMessages.
What am I doing wrong? 🤔
As far as I can see you have done this correctly. The config seems fine.
That profile is not assignable to CollectionSlug is probably because your types are not generated, so typescript does not know about it yet.
I see you use yarn so try
yarn generate:typesor
yarn payload generate:types, it depends a bit on what is in your package.json how you run it.
You find more details about it here:
https://payloadcms.com/docs/typescript/generating-typesDamn, didn't realize I forgot to generate the types. Thanks! That fixed it
Star
Discord
online
Get dedicated engineering support directly from the Payload team.