@nuxt/content: v1.0.0
@nuxt/typescript-runtime: v0.4.0
@nuxt/typescript-build: v0.6.0
nuxt: v2.12.2
https://github.com/tanakakjs/nuxt-blog
The project generated by create-nuxt-app. (spa & typescript)
npm run generate 17:21 Property '$content' does not exist on type 'Context'.
15 |
16 | export default Vue.extend({
> 17 | async asyncData({ $content, params, error }) {
| ^
18 | let posts
19 | try {
20 | posts = await $content('post')
What is the right way to deal with it?
I was able to get around it in the @ts-ignore comment, but I'm not sure I'm right.
export default Vue.extend({
// @ts-ignore
async asyncData({$content}) {
......
}
})
hey @tanakakjs, I had the same issue today and when I was googling it I found your question here! 馃槅
Adding @ts-ignore is probably the simplest solution. Although I tackled it in a bit different way. I created types/nuxt.d.ts inside my project with the following content:
import { Context } from '@nuxt/types'
declare module '@nuxt/types' {
export interface Context {
$content(...args: any): any
}
}
Probably it's not any better than yours because any types gives no clues for better type checks. However it successfully compiles the source code at least.
I believe we need to wait until @nuxt/content release typings...
@nuxt/content: v1.0.0
@nuxt/typescript-build: v1.0.0
@nuxt/types" v0.7.6
nuxt: v2.12.2
Hey guys,
Types have been added in v1.0.2, so you should not encounter this error anymore.
You just have to add @nuxt/content in your types as stated here: https://content.nuxtjs.org/installation/#typescript.
Let me know if you still have an issue and you're welcome to open a PR to improve types if needed https://github.com/nuxt/content/blob/master/types/index.d.ts.
Most helpful comment
Hey guys,
Types have been added in v1.0.2, so you should not encounter this error anymore.
You just have to add
@nuxt/contentin your types as stated here: https://content.nuxtjs.org/installation/#typescript.Let me know if you still have an issue and you're welcome to open a PR to improve types if needed https://github.com/nuxt/content/blob/master/types/index.d.ts.