Skip to content

Nuxt 3 + Strapi 4 + TypeScript error #461

@MilanTearMaras

Description

@MilanTearMaras

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions