PageProps & TypeScript erros in next v15.0.0-canary.179
Answered
Canada Warbler posted this in #help-forum
Canada WarblerOP
Bellow, the code of my invoices page:
When I create the production optimizaed build using
What's wrong?
Thx for your help
import Pagination from '@/app/ui/invoices/pagination';
import Search from '@/app/ui/search';
import Table from '@/app/ui/invoices/table';
import { CreateInvoice } from '@/app/ui/invoices/buttons';
import { lusitana } from '@/app/ui/fonts';
import { InvoicesTableSkeleton } from '@/app/ui/skeletons';
import { Suspense } from 'react';
import { fetchInvoicesPages } from '@/app/lib/data';
export default async function Page({
searchParams,
}: {
searchParams?: {
query?: string;
page?: string;
};
}) {
const query = searchParams?.query || '';
const currentPage = Number(searchParams?.page) || 1;
const totalPages = await fetchInvoicesPages(query);
return (
<div className="w-full">
...
</div>
);
}When I create the production optimizaed build using
pnpm run build, I got the following TypeScript error:app/dashboard/invoices/page.tsx
Type error: Type '{ searchParams?: { query?: string | undefined; page?: string | undefined; } | undefined; }' does not satisfy the constraint 'PageProps'.
Types of property 'searchParams' are incompatible.
Type '{ query?: string | undefined; page?: string | undefined; } | undefined' is not assignable to type 'Promise<any> | undefined'.
Type '{ query?: string | undefined; page?: string | undefined; }' is missing the following properties from type 'Promise<any>': then, catch, finally, [Symbol.toStringTag]What's wrong?
Thx for your help
6 Replies
so
const query = (await searchParams)?.query || ''Answer
@@ts-ignore in next 15, the apis like `searchParams` and `params` returns a promise
Canada WarblerOP
Thx for you info, have you got an example of using
searchParams and/or params with promise?@@ts-ignore https://github.com/vercel/next.js/pull/68812
Canada WarblerOP
Thx for the link to this PR, I'm reading it
Canada WarblerOP
That's solve my issue. Thx