TypeScript support
See original GitHub issueHello. I just encountered this error when using nuxt with Typescript.
20:2 No overload matches this call. Overload 1 of 2, '(options: ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>> & ThisType<...>): <VC extends VueClass<...>>(target: VC) => VC', gave the following error. Type '({ $prismic }: { $prismic: any; }) => { posts: any; }' is not assignable to type '(ctx: Context) => void | object | Promise<void | object>'. Types of parameters '__0' and 'ctx' are incompatible. Property '$prismic' is missing in type 'Context' but required in type '{ $prismic: any; }'. Overload 2 of 2, '(target: VueClass<Vue>): VueClass<Vue>', gave the following error. Argument of type '{ asyncData({ $prismic }: { $prismic: any; }): { posts: any; }; components: { ImageBlock: typeof ImageBlock; Paragraph: typeof Paragraph; Card: typeof Card; CallToAction: typeof CallToAction; }; head: { ...; }; }' is not assignable to parameter of type 'VueClass<Vue>'. Object literal may only specify known properties, and 'asyncData' does not exist in type 'VueClass<Vue>'.
My code:
async asyncData ({ $prismic } : { $prismic : any }) {
...
}
My solution was to use $prismic
like this:
async asyncData () {
const { $prismic } = Vue.prototype.$nuxt
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Hey, I guess it was from here: https://github.com/prismicio/prismic-vue/issues/5, really looking forward to move our kit to typescript properly this year ☺️
The new version of the module targetting Nuxt 3 comes with first-class TypeScript support 🎉
https://v3.prismic.nuxtjs.org/