vercel / vercel/next-learn

Chapter 11; 4. Updating the table wrong type

Open
#667 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.8k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Chapter 11 page code and the referenced table.tsx declaration, then reproduce the TypeScript error at the Table call. Check how searchParams are typed in this lesson and verify the example type-checks successfully after the correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, typescript
Domain
documentation
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.