我使用NextJS和Typescript。在主异步页面中,我得到客户端报价const clientQuotes: IQuote[] = await getAllQuotes();
。
IQuote接口具有以下形式:
export interface IQuote {
id: string
dateTimeAdded: string
hasBeenPaid: boolean
completed: boolean
dateTimeNeeded: string
nameClient: string
numberOfVechicles: number
serviceRequired: string
phoneNumber: string
clientEmail: string
detailsOfQuote: string
};
我得到的响应是一个普通的对象数组。[{}, {}]
,填写上面的信息。
接下来,我创建了另一个组件,并在其中传递了带有prop quotes
的数组。但是,此 prop 以红色突出显示。<UncompletedQuotes quotes={clientQuotes}/>
错误是Type '{ quotes: IQuote[]; }' is not assignable to type 'IntrinsicAttributes & IQuoteList'. Property 'quotes' does not exist on type 'IntrinsicAttributes & IQuoteList'.ts(2322)
,我不明白...
import React, { FC } from 'react'
export interface IQuote {
id: string
dateTimeAdded: string
hasBeenPaid: boolean
completed: boolean
dateTimeNeeded: string
nameClient: string
numberOfVechicles: number
serviceRequired: string
phoneNumber: string
clientEmail: string
detailsOfQuote: string
};
interface IQuoteList extends Array<IQuote>{};
const UncompletedQuotes: FC<IQuoteList> = (quotes) => {
console.log(quotes);
return (
<section>
</section>
)
}
export default UncompletedQuotes
问题还在于,如果我登录控制台,prop发送我得到一个对象,其中包含一个名为quotes的键。因此,为了得到一个简单的对象数组,我得到了以下形式的东西:{quotes: [{id, dateTime, etc}, {id, dateTime, etc}]}
1条答案
按热度按时间goqiplq21#
试试这个:
希望对你有帮助:D