Hey @leopold thanks for reaching out!
I have trouble reproducing your issue on the latest version of @nuxtjs/prismic
(3.0.3), providing the latest @prismicio/vue
(4.1.0) and @prismicio/client
(7.3.1)
I suspect this is due to an old version of @prismicio/types
you're using. @prismicio/types
has been deprecated in favor of @prismicio/client
at the beginning of this Summer. All its types are now exposed through @prismicio/client
. This change was made to reduce the amount of type mismatch issues like the one you're experiencing above.
To fix it, ensure you're running our SDKs' latest version. You can run the following to update them:
npm update @nuxtjs/prismic @prismicio/vue @prismicio/client
Then, the updated snippet should be looking something like this (with just the import changed):
import { usePrismicText } from '@prismicio/vue'
import type { TitleField, RichTextField } from '@prismicio/client'
export default function (titleField: TitleField | RichTextField) {
if (usePrismicText({ field: titleField }).text.value.length > 0) {
return usePrismicText({ field: titleField }).text.value
} else {
return null
}
}
If the above doesn't solve your issue, can you provide the list of Prismic dependencies you're running with? Running those commands can help you get that info:
npm ls @nuxtjs/prismic
npm ls @prismicio/vue
npm ls @prismicio/client
npm ls @prismicio/types
On an unrelated note, I'm curious what's your use case for using usePrismicText
(a Vue composable) in a JavaScript util function? Just in case, the asText
helper from @prismicio/client
can help achieve similar results. @prismicio/client
also exposes an isFilled
helper with methods to check if fields are filled, allowing for such potential refactor:
import { asText, isFilled, type TitleField, type RichTextField } from '@prismicio/client'
export default function (field: TitleField | RichTextField) {
return isFilled.richText(field) ? asText(field) : null
// This also works but is less explicit
// return asText(field) || null
}