Hi,
I am having some issues where the types aren't matching up when referring to a collection slug in various places.
type '"blog-posts"' is not assignable to type 'CollectionSlug'.ts(2322)
find.d.ts(6, 5): The expected type comes from property 'collection' which is declared here on type 'Options<CollectionSlug, SelectFromCollectionSlug<CollectionSlug>>'Page:
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
const { isEnabled: draft } = await draftMode()
const payload = await getPayload({
config: payloadConfig,
})
const posts = await payload.find({
collection: 'blog-posts',
limit: 1,
draft,
overrideAccess: draft,
pagination: false,
where: {
slug: {
equals: slug,
},
},
})
const post = posts.docs[0]
if (!post) {
return notFound()
}
return (
<>
{/* ... */}
</>
)
}payload-config.ts located in src/features/payload/payload.config.ts
export default buildConfig({
admin: {
// ...
},
collections: [Users, Media, Dummy, Tenants, LandingPages, BlogPosts],
editor: lexicalEditor({}),
secret: process.env.PAYLOAD_SECRET || '',
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
db: sqliteAdapter({
client: {
url: process.env.DATABASE_URI || '',
},
}),
sharp,
plugins: [
//...
],
})The payload-types.ts file is located in src/features/payload/payload-types.ts.
Running payload generate:types does not change the payload-types file, it is already up to date.
Have tried setting env variable with path to the config in case that was the issue, but that hasn't changed anything.
Im sure it's something that we've changed or done since starting with payload that has made it stop working, as it works fine on the website example repo for me.
can you show your
BlogPostsconfig as well?
and in
src/features/payload/payload-types.ts, do you see
blog-posts?
export const BlogPosts: CollectionConfig = {
slug: 'blog-posts',
access: {
create: () => true,
delete: () => true,
read: () => true,
update: () => true,
},
admin: {
useAsTitle: 'title',
defaultColumns: ['title'],
livePreview: {
url: ({ data, req }) => {
return generatePreviewPath({
slug: typeof data.slug === 'string' ? data.slug : '',
collection: 'blog-posts',
req,
})
},
},
},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
name: 'slug',
type: 'text',
required: true,
unique: true,
index: true,
admin: {
position: 'sidebar',
},
},
// trimmed to save chars
],
versions: {
drafts: {
autosave: {
interval: 100,
},
schedulePublish: true,
},
maxPerDoc: 50,
},
}lol, I had an old payload-types in src/payload-types from before someone else moved it into src/features/payload/payload-types.ts
Sometimes you gotta type it out to figure out the problem 🤦
Star
Discord
online
Get dedicated engineering support directly from the Payload team.