'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'.
Solution 1:[1]
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) => {
// ...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mddg |
