KomaSattarovK
Convex Community3y ago
7 replies
KomaSattarov

Constantly getting this error and cant get pass by

const topics = useQuery(api.titles.collectTitles);

  const filteredTopics = useMemo(
    () =>
      Object.entries(topics).reduce((acc, [key, topic]) => {
        if (
          fields.categories.length > 0 &&
          (!topic.category || !fields.categories.includes(topic.category))
        ) {
          return acc;
        }
        if (
          fields.questionTypes.length > 0 &&
          !fields.questionTypes.includes(topic.questionType as string)
        ) {
          return acc;
        }
        if (
          fields.search &&
          !topic.name.toLowerCase().includes(fields.search.toLowerCase()) &&
          !topic.questionDesc
            ?.toString()
            .toLowerCase()
            .includes(fields.search.toLowerCase())
        ) {
          return acc;
        }
        acc?.push(topic);
        return acc;
      }, {} as typeof topics),
    [fields, topics]
  );

Type 'undefined' is not assignable to type '{}'.ts(2769)


This error is showing up here when the topics is declared Object.entries(topics).reduce
Was this page helpful?