Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(typedRoutes): fixed StaticRoutes and DynamicRoutes being empty causing invalid syntax #46620

Merged
merged 6 commits into from
Mar 1, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/next/src/build/webpack/plugins/next-types-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function createRouteDefinitions(
}
}

const fallback = !edgeRoutes.length && !nodeRoutes.length ? 'string' : ''
const routes = [...edgeRoutes, ...nodeRoutes, ...extraRoutes]

// By exposing the static route types separately as string literals,
Expand Down Expand Up @@ -238,6 +237,9 @@ function createRouteDefinitions(
addRouteToRouteTypes(route)
}

const staticRouteTypesFallback = staticRouteTypes ? '' : 'string'
const dynamicRouteTypesFallback = dynamicRouteTypes ? '' : 'string'

DuCanhGH marked this conversation as resolved.
Show resolved Hide resolved
return `// Type definitions for Next.js routes

/**
Expand Down Expand Up @@ -267,10 +269,10 @@ declare namespace __next_route_internal_types__ {
type OptionalCatchAllSlug<S extends string> =
S extends \`\${string}\${SearchOrHash}\` ? never : S

type StaticRoutes = ${staticRouteTypes}
type DynamicRoutes<T extends string = string> = ${dynamicRouteTypes}
type StaticRoutes = ${staticRouteTypesFallback}${staticRouteTypes}
type DynamicRoutes<T extends string = string> = ${dynamicRouteTypesFallback}${dynamicRouteTypes}
DuCanhGH marked this conversation as resolved.
Show resolved Hide resolved

type RouteImpl<T> = ${fallback}
type RouteImpl<T> =
| StaticRoutes
| \`\${StaticRoutes}\${Suffix}\`
| (T extends \`\${DynamicRoutes<infer _>}\${Suffix}\` ? T : never)
Expand Down