Generated route types
What you need to know
Next.js can generate TypeScript helpers from its route tree. These helpers describe route parameters and layout slots, reducing handwritten types that drift when the app changes.
By the end, you can: use appropriate PageProps and LayoutProps; explain type generation.
Type a dynamic page and its layout
// app/catalog/[slug]/page.tsxexport default async function Page(props: PageProps<'/catalog/[slug]'>) { const {slug} = await props.params; return <h1>Requested book: {slug}</h1>;}Expected behavior: /catalog/fern displays Requested book: fern. The example displays the request value, not evidence of a matching database row.
How it works
For App Router routes use global PageProps<'/catalog/[slug]'>, LayoutProps<'/catalog/[slug]'> and RouteContext<'/api/catalog/[slug]'> in the matching file. Route parameter access is asynchronous in this teaching lane. A page may also receive searchParams, while layout props describe children and named slots. These helpers are generated rather than imported from a separate package. Run next typegen before tsc --noEmit in an approved project, or let next dev/build generate types. Include generated declarations according to the framework-generated tsconfig; do not hand-edit them to silence an error. Type generation evaluates configuration, so use reviewed configuration and dependencies only. A route parameter being typed string does not mean the requested book exists. Keep lookup validation and not-found handling separate.
Type a Route Handler context
// app/api/catalog/[slug]/route.tsexport async function GET(_: Request, ctx: RouteContext<'/api/catalog/[slug]'>) { const {slug} = await ctx.params; return Response.json({requestedSlug: slug});}Expected behavior: GET /api/catalog/moss returns the requested slug in JSON; no database read occurs.
Common mistake
Using params.slug directly when params is a Promise produces the wrong contract. Await params. A type-only syntax check does not establish that the generated route actually exists.
Practice and verification
Given the tree app/catalog/[slug]/layout.tsx and page.tsx, write a layout with LayoutProps and render children. In an approved app run typegen then tsc; rename the segment and verify that stale route literals are rejected.
Scope: App Router, proposed Next.js 16.x, React 19 family, Cache Components disabled. Framework snippets are static or explicitly partial; actual browser, auth and generated-route checks are pending. SQLite exercises run separately in the authoring environment, not the ByteMind evaluator.