My app is running well. It is very slow in development mode. So i tried to build it. During build i’m getting type error. i tried to figure it out but still facing.
import { databases, users } from "@/models/server/config";
import {
answerCollection,
db,
voteCollection,
questionCollection
} from "@/models/name";
import { Query } from "node-appwrite";
import React from "react";
import Link from "next/link";
import ShimmerButton from "@/components/magicui/shimmer-button";
import QuestionCard from "@/components/QuestionCard";
import { UserPrefs } from "@/store/Auth";
import Pagination from "@/components/Pagination";
import Search from "./Search";
const Page = async ({
searchParams
}: {
searchParams: { page?: string; tag?: string; search?: string };
}) => {
searchParams.page ||= "1";
const queries = [
Query.orderDesc("$createdAt"),
Query.offset((+searchParams.page - 1) * 25),
Query.limit(25)
];
if (searchParams.tag) queries.push(Query.equal("tags", searchParams.tag));
if (searchParams.search)
queries.push(
Query.or([
Query.search("title", searchParams.search),
Query.search("content", searchParams.search)
])
);
const questions = await databases.listDocuments(
db,
questionCollection,
queries
);
questions.documents = await Promise.all(
questions.documents.map(async (ques) => {
const [author, answers, votes] = await Promise.all([
users.get<UserPrefs>(ques.authorId),
databases.listDocuments(db, answerCollection, [
Query.equal("questionId", ques.$id),
Query.limit(1) // for optimization
]),
databases.listDocuments(db, voteCollection, [
Query.equal("type", "question"),
Query.equal("typeId", ques.$id),
Query.limit(1) // for optimization
])
]);
return {
...ques,
totalAnswers: answers.total,
totalVotes: votes.total,
author: {
$id: author.$id,
reputation: author.prefs.reputation,
name: author.name
}
};
})
);
return (
<div className="container mx-auto px-4 pb-20 pt-36">
<div className="mb-10 flex items-center justify-between">
<h1 className="text-3xl font-bold">All Questions</h1>
<Link href="/questions/ask">
<ShimmerButton className="shadow-2xl">
<span className="whitespace-pre-wrap text-center text-sm font-medium leading-none tracking-tight text-white dark:from-white dark:to-slate-900/10 lg:text-lg">
Ask a question
</span>
</ShimmerButton>
</Link>
</div>
<div className="mb-4">
<Search />
</div>
<div className="mb-4">
<p>{questions.total} questions</p>
</div>
<div className="mb-4 max-w-3xl space-y-6">
{questions.documents.map((ques) => (
<QuestionCard key={ques.$id} ques={ques} />
))}
</div>
<Pagination total={questions.total} limit={25} />
</div>
);
};
export default Page;
during build i’m getting below error ::
Linting and checking validity of types ..Failed to compile.
.next/types/app/questions/ask/page.ts:28:13
Type error: Type 'OmitWithTag<{ question: Document; }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'question' is incompatible with index signature.
Type 'Document' is not assignable to type 'never'.
26 |
27 | // Check the prop type of the entry function
> 28 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
27 | // Check the prop type of the entry function
> 28 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
> 28 | checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
| ^
29 |
30 | // Check the arguments and return type of the generateMetadata function
31 | if ('generateMetadata' in entry) {
i’ve checked it out but not able to solve it.
later i run the command npx tsc –noEmit and it tells me about error.
$ npx tsc --noEmit
.next/types/app/questions/ask/page.ts:28:13 - error TS2344: Type 'OmitWithTag<{ question: Document; }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.
Property 'question' is incompatible with index signature.
Type 'Document' is not assignable to type 'never'.
28 checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.next/types/app/questions/ask/page.ts:28:29 - error TS2559: Type '{ question: Document; }' has no properties in common with type 'PageProps'.
28 checkFields<Diff<PageProps, FirstArg<TEntry['default']>, 'default'>>()
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 2 errors in the same file, starting at: .next/types/app/questions/ask/page.ts:28
i don’t know how to solve it. what’s going on here?
please resolve it.