mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
46e2114ea2
## Summary Generate type definitions for `next/root-params` from App Router root layouts. This adds a `root-params.d.ts` file under `.next/types` during build, `next dev`, and `next typegen`, so imports from `next/root-params` get accurate autocomplete and type checking. ## What Changed - Collect root param metadata from layout routes in the route types manifest - Generate `.next/types/root-params.d.ts` for `next/root-params` - Emit root param types in `next build/dev/typegen` - Infer `undefined` only when a param is not present in every root layout - Model mixed root param shapes correctly as unions - For example, `string | string[] | undefined` when the same param name appears with different shapes across roots - Remove stale `root-params.d.ts` when the feature is disabled or there are no root params ## Why `next/root-params` already works at runtime, but its types were not tailored to the current app. This change closes that gap by generating declarations from the app's actual root layouts. Required params stay required for single-root apps, while multi-root apps correctly expose params that may be missing or have mixed segment shapes. ## Testing - Added focused unit tests for root param type generation - Added a typecheck e2e test for generated `root-params.d.ts`
4 lines
194 B
TypeScript
4 lines
194 B
TypeScript
// The actual types are generated into .next/types/root-params.d.ts and wired
|
|
// via next-env.d.ts. This bare declaration avoids type errors before generation.
|
|
declare module 'next/root-params'
|