我创建了这样一个函数:
type MainProps = { sticky: boolean, refStickyElement: any };
export const MainBlog = ({ sticky, refStickyElement }: MainProps,mposts: TPost[]) => {
...但是,当我想在另一个函数中使用这个函数时,我得到了错误:
const {results} = data
let posts: Array<TPost> = results;
<MainBlog refStickyElement={element} sticky={isSticky} posts={posts} />错误为posts={posts}
Type '{ refStickyElement: MutableRefObject<null>; sticky: boolean; posts: TPost[]; }' is not assignable to type 'IntrinsicAttributes & MainProps'.
Property 'posts' does not exist on type 'IntrinsicAttributes & MainProps'.发布于 2022-04-26 08:34:57
如果要传递posts作为支柱,则必须将其添加到MainProps类型中。function函数组件只有一个param,它是一个对象(道具)。
因此,您必须将MainProps类型更改为:
type MainProps = { sticky: boolean, refStickyElement: any, posts: TPost[] };
export const MainBlog = ({ sticky, refStickyElement, posts }: MainProps) => {
// ...
}https://stackoverflow.com/questions/72005795
复制相似问题