N
Nuxt3mo ago
Uchuu

const { data: home } = await useAsyncData('leeds', () => queryCollection('uniofleeds').first())

Argument of type '"uniofleeds"' is not assignable to parameter of type '"content"'. import { defineContentConfig, defineCollection } from '@nuxt/content' import { z } from 'zod' export default defineContentConfig({ collections: { content: defineCollection({ type: 'page', source: '/*.md' }), uniofleeds: defineCollection({ type: "data", schema: z.object({ university: z.string(), modules: z.array( z.object({ name: z.string(), questions: z.array( z.object({ question: z.string(), answers: z.tuple([ z.string(), z.string(), z.string(), z.string() ]) }) ) }) ) }), source: '/uniofleeds.json' }) } })
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Uchuu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error
Argument of type '"uniofleeds"' is not assignable to parameter of type '"content"'.
Argument of type '"uniofleeds"' is not assignable to parameter of type '"content"'.
means that the type for the argument of queryCollection does not recognize "uniofleeds" as a valid collection key. This usually happens when TypeScript does not pick up your custom collection names from your content.config.ts file. Why does this happen? - TypeScript types for queryCollection are generated based on your Nuxt Content configuration. If the type system only knows about the default "content" collection, it will not accept "uniofleeds" as a valid argument. - This can occur if the Nuxt Content module has not picked up your custom content.config.ts changes, or if type generation is out of sync. How to fix: 1. Restart your dev server after adding or changing collections in content.config.ts. This allows Nuxt Content to regenerate types and recognize your new collection keys. 2. Check your file structure and naming: Make sure your content.config.ts is at the project root and is named correctly. 3. Check for build errors: If there are errors in your config or schema, type generation may fail. Example of correct usage: Your content.config.ts is correct:
import { defineContentConfig, defineCollection } from '@nuxt/content'
import { z } from 'zod'
export default defineContentConfig({
collections: {
content: defineCollection({
type: 'page',
source: '**/*.md'
}),
uniofleeds: defineCollection({
type: "data",
schema: z.object({
university: z.string(),
modules: z.array(
z.object({
name: z.string(),
questions: z.array(
z.object({
question: z.string(),
answers: z.tuple([
z.string(),
z.string(),
z.string(),
z.string()
])
})
)
})
)
}),
source: '**/uniofleeds.json'
})
}
})
import { defineContentConfig, defineCollection } from '@nuxt/content'
import { z } from 'zod'
export default defineContentConfig({
collections: {
content: defineCollection({
type: 'page',
source: '**/*.md'
}),
uniofleeds: defineCollection({
type: "data",
schema: z.object({
university: z.string(),
modules: z.array(
z.object({
name: z.string(),
questions: z.array(
z.object({
question: z.string(),
answers: z.tuple([
z.string(),
z.string(),
z.string(),
z.string()
])
})
)
})
)
}),
source: '**/uniofleeds.json'
})
}
})
And your query should work:
const { data: home } = await useAsyncData('leeds', () => queryCollection('uniofleeds').first())
const { data: home } = await useAsyncData('leeds', () => queryCollection('uniofleeds').first())
If you still get the error after restarting: - Make sure you are using a recent version of Nuxt Content v3, as collection type inference and type generation are features of v3+. - If you are using a custom TypeScript setup, ensure your tsconfig.json includes the Nuxt Content types. Summary:
This is a type generation issue, not a runtime bug. Restarting your dev server after editing content.config.ts should resolve it, as Nuxt Content will regenerate the types and recognize "uniofleeds" as a valid collection key. For more on defining and querying collections, see the official docs: Define Content Collections, Query Collection. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@1035470271441805353> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?