next-learn
next-learn copied to clipboard
Chapter 11; 4. Updating the table wrong type
export default async function Page({
searchParams,
}: {
searchParams?: {
query?: string;
page?: string;
};
}) {
const query = searchParams?.query || '';
const currentPage = Number(searchParams?.page) || 1;
This code gives an error here:
<Table query={query} currentPage={currentPage} />
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.ts(2322)
table.tsx(12, 3): The expected type comes from property 'currentPage' which is declared here on type 'IntrinsicAttributes & { query: string; currentPage: number; }'
After changing page prop type to number it works
searchParams?: { query?: string; page?: number };