ll_logs
(Piotr Zieliński)
January 17, 2024, 12:42am
1
Hey, I created nuxtjs app with slicemachine. I still have problems with Typescript. When I fetch something from the API, the wrong types are assigned to it. Or I'm doing something wrong.
That's what I mean.
That's one of the code, where I'm fetching data and then I iterates over the array where unfortunately I cannot access my navi_link. This is one of the slice.
That's type script error I getting.
The page is working, but I don't know if there's something I'm doing wrong and this error in vsc annoys me
Hi Piotr,
My best guess is that you need an isFilled()
guard here, maybe something like:
<li
v-for="(item, i) in home?.data.navi_link"
v-if="$prismic.isFilled(home?.data.navi_link)"
:key="i"
/>
Let me know if that helps.
Sam
ll_logs
(Piotr Zieliński)
January 17, 2024, 3:45pm
5
Hey, I tried that and that is result.
Btw even if I tried in diffrent way it doesn't work as well. The message is still the same.
Hi Piotr,
I think I misread your code. Is navi_link
a content relationship?
If that's the case, do you have GraphQuery or FetchLinks implemented and working properly?
If so, to get the type working you'll need a little workaround, which you can find here:
There are some threads about similar issues, but I still wanted to post.
The following template code (Vue/Nuxt) gives me the error below. Could I use some helper function in the template code to fix this? isFilled? Thanks in advance.
<ComponentLegalClause
v-else-if="slice.slice_type === 'legal_clause' && slice.primary.clause"
:structured-text-field="slice.primary.clause.data.text"
/>
Property 'data' does not exist on type 'ContentRel…
Sam