Chapter 11; 4. Updating the table wrong type
Open
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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