Answer the question
In order to leave comments, you need to log in
TypeScript throws error: Type cannot be assigned to type 'IntrinsicAttributes & "" & { children?: ReactNode; }", how to fix this?
Hello, I'm doing a small pet project to improve my skills in TS.
I receive data from the server, I seem to be able to type them normally, the posts started to be displayed without errors, but then I decided to put the code with iteration into a separate component, and ts immediately gave an error:
Тип "{ posts: IPost[]; }" не может быть назначен для типа "IntrinsicAttributes & IPost & { children?: ReactNode; }".
Свойство "posts" не существует в типе "IntrinsicAttributes & IPost & { children?: ReactNode; }"
export const Main: FC= () => {
const [posts, setPosts] = useState<IPost[]>([]);
useEffect(() => {
try {
const fetchPost = async () => {
const res = await axios.get('/posts');
setPosts(res.data);
};
fetchPost();
} catch (error) {
console.log(error);
}
}, []);
return (
<>
<div className='main-container'>
<NewPosts />
<PostSort />
<Posts posts={posts} />
</div>
</>
);
};
export const Posts: FC<IPost> = ({ posts }) => {
return (
<div className='post-container'>
{posts.map((post) => (
<Post key={post._id} post={post} />
))}
</div>
);
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question