S.M_Emamian
S.M_Emamian

Reputation: 17383

Type is not assignable to type IntrinsicAttributes

I have create a function like this:

type MainProps = { sticky: boolean, refStickyElement: any };
export const MainBlog = ({ sticky, refStickyElement }: MainProps,mposts: TPost[]) => {
...

but when I want to use this function at another function I got error:

  const {results} = data
  let posts: Array<TPost> = results;
 <MainBlog refStickyElement={element} sticky={isSticky} posts={posts} />

error is for 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'.

Upvotes: 0

Views: 100

Answers (1)

mddg
mddg

Reputation: 695

If you want to pass posts as a prop, you have to add it to the MainProps type. React function components only have one param, which is an object (the props).
Therefore, you would have change your MainProps type to:

type MainProps = { sticky: boolean, refStickyElement: any, posts: TPost[] };

export const MainBlog = ({ sticky, refStickyElement, posts }: MainProps) => {
  //  ...
}

Upvotes: 1

Related Questions