Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/next/src/server/lib/router-utils/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,29 @@ declare module 'next' {

export type Route<T extends string = string> =
__next_route_internal_types__.RouteImpl<T>

/**
* 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<T extends string = string> = __next_route_internal_types__.DynamicRoutes<T>
}

declare module 'next/link' {
Expand Down
25 changes: 25 additions & 0 deletions packages/next/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ export type { Instrumentation } from './server/instrumentation/types'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type Route<RouteInferType = any> = 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' {
// <html amp=""> support
Expand Down
Loading