@tostershmoster

Type '{}' is missing the following properties... Как исправить?

Код выводит посты
// Feed.tsx
const [posts, setPosts] = useState<IPost[]>([]);

useEffect(
  () =>
    onSnapshot(query(collection(db, 'posts'), orderBy('timestamp', 'desc')), (snapshot: any) => {
      setPosts(snapshot.docs);
    }),
  [],
);

return (
...
  {posts.map((item) => {
    return <Post key={item.id} id={item.id} post={item.data()} />; // error
  })}
...
)


параметр post подчёркивается с ошибкой
(property) IPostProps.post: IPost
Type '{}' is missing the following properties from type 'IPost': id, userImage, username, tag, and 4 more.ts(2740)
Post.tsx(49, 3): The expected type comes from property 'post' which is declared here on type 'IntrinsicAttributes & IPostProps'


// Post.tsx
interface IPost {
  id: string;
  userImage: string;
  username: string;
  tag: string;
  timestamp: any;
  text: string;
  image: string;
  data: () => {};
}

interface IPostProps {
  id: string;
  post: IPost;
  postPage?: boolean;
}

const Post: FC<IPostProps> = ({ id, post, postPage }) => {...}


В dev режиме работает, build падает с той же ошибкой
  • Вопрос задан
  • 237 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы