首页 > 解决方案 > 接口道具声明

问题描述

我是 Typescript 的新手,我被一些界面道具困住了。有一个错误说“属性'服务'不存在类型'IntrinsicAttributes & AkkordionProps [] ”,我不明白,因为我在我的接口声明中看到了服务,所以我现在迷失了。

这是调用 BusinessPage 组件的主要组件:

<BusinessPage services={services} />

这是 BusinessPage.tsx 组件:

  export interface AkkordionListProps {
  services: {
    name: string
    services: {
      name: string
      content: string
      link: string
    }[]
  }
}

export interface AkkordionProps {
  services: AkkordionListProps[]
}

export const BusinessPage = (services: AkkordionProps[]): JSX.Element => {}

谢谢 :)

标签: reactjstypescriptinterfacetypeerror

解决方案


BUsinessPage是反应组件。React 总是期望一个对象作为 prop 而不是数组:

import React from 'react'

export interface AkkordionListProps {
    services: {
        name: string
        services: {
            name: string
            content: string
            link: string
        }[]
    }
}

export interface AkkordionProps {
    services: AkkordionListProps[]
}

export const BusinessPage = (props: AkkordionProps): JSX.Element => {
    return <div></div>
}

操场


推荐阅读