Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing response from find #410

Closed
tjventurini opened this issue Apr 7, 2024 · 1 comment
Closed

Typing response from find #410

tjventurini opened this issue Apr 7, 2024 · 1 comment
Labels
question Further information is requested

Comments

@tjventurini
Copy link

tjventurini commented Apr 7, 2024

Hi 👋

I'm new to this and I'm trying to work with the response of find but can't get the typing right.

This is how I use it.

<script setup lang="ts">
import type { Page } from '@/types/page'

const { find } = useStrapi()

const {
  data: pages,
  pending,
  status,
  refresh,
  error: pagesError,
} = await useAsyncData('pages', () => find<Page>('pages'))
</script>
export interface PageAttributes {
  title: string
}

export interface Page {
  id: string
  attributes: PageAttributes
}

So far so good. But when I try to use the response I get a type error, title does not exist on attributes of Page.

[vue-tsc] Property 'title' does not exist on type 'Page'.
<ul>
  <li v-for="page in pages?.data">Title: {{ page.attributes.title }}</li>
</ul>

image

What do I need to do, so the type of Page can be used and for example the title is available to me?

Thank you :)

@tjventurini tjventurini added the question Further information is requested label Apr 7, 2024
@tjventurini
Copy link
Author

Okey, I just found my problem 😅

The issue was the Page interface. Here is the working one.

export interface Page {
  title: string
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants