Skip to content

Commit fcfab17

Browse files
authored
Fix(typedRoutes): fixed StaticRoutes and DynamicRoutes being empty causing invalid syntax (vercel#46620)
When `dynamicRouteTypes`/`staticRouteTypes` is empty, an invalid `link.d.ts` is generated. This just handles that case. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent 844776e commit fcfab17

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/next/src/build/webpack/plugins/next-types-plugin.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ function createRouteDefinitions(
196196
}
197197
}
198198

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

202201
// By exposing the static route types separately as string literals,
@@ -267,10 +266,12 @@ declare namespace __next_route_internal_types__ {
267266
type OptionalCatchAllSlug<S extends string> =
268267
S extends \`\${string}\${SearchOrHash}\` ? never : S
269268
270-
type StaticRoutes = ${staticRouteTypes}
271-
type DynamicRoutes<T extends string = string> = ${dynamicRouteTypes}
269+
type StaticRoutes = ${staticRouteTypes || 'string'}
270+
type DynamicRoutes<T extends string = string> = ${
271+
dynamicRouteTypes || 'string'
272+
}
272273
273-
type RouteImpl<T> = ${fallback}
274+
type RouteImpl<T> =
274275
| StaticRoutes
275276
| \`\${StaticRoutes}\${Suffix}\`
276277
| (T extends \`\${DynamicRoutes<infer _>}\${Suffix}\` ? T : never)

0 commit comments

Comments
 (0)