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

Nuxt 3 + Strapi 4 + TypeScript error #461

Open
MilanTearMaras opened this issue Feb 4, 2025 · 0 comments
Open

Nuxt 3 + Strapi 4 + TypeScript error #461

MilanTearMaras opened this issue Feb 4, 2025 · 0 comments
Labels
question Further information is requested

Comments

@MilanTearMaras
Copy link

MilanTearMaras commented Feb 4, 2025

Hello there!

I am fairly new to TypeScript and I wanted to create a Nuxt 3 app with Strapi 4 with TypeScript. On Strapi I have plugins "strapi-plugin-transformer" for flattening my response and "shemas-to-ts" for generating TS types. So far everything worked quite well but now I have been stuck for a while on, I bet pretty simple stuff. I have single type in Strapi called Header and I am trying to load all data on FE. I took the generated type from Strapi which looks like this:

export interface Header_Plain {
    id: number;
    createdAt: Date;  updatedAt: Date;  publishedAt?: Date;  logo: Media_Plain;
    Link: HeaderLink_Plain[];
    locale: string;
    localizations?: Header_Plain[];
}

then, in my Nuxt, I have this code:

<script setup lang="ts">
const { find } = useStrapi()

const headerData = ref<Header_Plain | null>(null)

const { data, execute } = await useAsyncData(
  'header',
  () => find<Header_Plain>('header', { populate: 'deep' })
)

function loadData() {
  execute()

  headerData.value = data.value?.data
}

onMounted(() => {
  loadData()
})
</script>

The problem I have is, that I get the data from BE but in my loadData function I am getting Vue: Type Strapi4ResponseData<Header_Plain>[] is not assignable to type error. I know that I probably should use findOne instead of find but when I use findOne the problem still occurs. Could anyone help me with this? I simply don't understand why my BE data are wrapped in this Strapi4ResponseData or how I should take them out.

@MilanTearMaras MilanTearMaras added the question Further information is requested label Feb 4, 2025
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

1 participant