He creado una función como esta:
type MainProps = { sticky: boolean, refStickyElement: any }; export const MainBlog = ({ sticky, refStickyElement }: MainProps,mposts: TPost[]) => { ...pero cuando quiero usar esta función en otra función, recibí un error:
const {results} = data let posts: Array<TPost> = results; <MainBlog refStickyElement={element} sticky={isSticky} posts={posts} /> el error es para 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'.Si desea pasar posts como apoyo, debe agregarlo al tipo MainProps . Los componentes de la función React solo tienen un parámetro, que es un objeto (los accesorios) .
Por lo tanto, tendría que cambiar su tipo de MainProps a:
type MainProps = { sticky: boolean, refStickyElement: any, posts: TPost[] }; export const MainBlog = ({ sticky, refStickyElement, posts }: MainProps) => { // ... }