diff --git a/packages/next/src/server/lib/router-utils/typegen.ts b/packages/next/src/server/lib/router-utils/typegen.ts index a04cddac5891e..e1ae7dbb7f380 100644 --- a/packages/next/src/server/lib/router-utils/typegen.ts +++ b/packages/next/src/server/lib/router-utils/typegen.ts @@ -295,6 +295,29 @@ declare module 'next' { export type Route = __next_route_internal_types__.RouteImpl + + /** + * All static routes in your application. + * @example + * \`\`\`ts + * import type { StaticRoutes } from 'next' + * const route: StaticRoutes = "/about" + * \`\`\` + */ + export type StaticRoutes = __next_route_internal_types__.StaticRoutes + + /** + * All dynamic routes in your application. + * + * The type parameter T represents the union of all possible values that can fill any dynamic segment in your routes. + * @example + * \`\`\`ts + * import type { DynamicRoutes } from 'next' + * // T applies to ALL dynamic segments across ALL routes + * const route: DynamicRoutes<"en" | "fr"> = "/en/about" + * \`\`\` + */ + export type DynamicRoutes = __next_route_internal_types__.DynamicRoutes } declare module 'next/link' { diff --git a/packages/next/src/types.ts b/packages/next/src/types.ts index 1799a84dcee02..17760ff77510e 100644 --- a/packages/next/src/types.ts +++ b/packages/next/src/types.ts @@ -59,6 +59,31 @@ export type { Instrumentation } from './server/instrumentation/types' // eslint-disable-next-line @typescript-eslint/no-unused-vars export type Route = string & {} +/** + * Stub static routes type before `next dev` or `next build` is run. + * Will be populated with actual static routes during build. + * @example + * ```ts + * import type { StaticRoutes } from 'next' + * const route: StaticRoutes = "/about" + * ``` + */ +export type StaticRoutes = never + +/** + * Stub dynamic routes type before `next dev` or `next build` is run. + * Will be populated with actual dynamic routes during build. + * + * The type parameter T represents the union of all possible values that can fill any dynamic segment in your routes. + * @example + * ```ts + * import type { DynamicRoutes } from 'next' + * // T applies to ALL dynamic segments across ALL routes + * const route: DynamicRoutes<"en" | "fr"> = "/en/about" + * ``` + */ +export type DynamicRoutes<_T extends string = string> = never + // Extend the React types with missing properties declare module 'react' { // support