next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

Chapter 11; 4. Updating the table wrong type

Open sk8higher opened this issue 1 year ago • 0 comments

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 };

sk8higher avatar May 07 '24 16:05 sk8higher