Unverified Commit fcfab172 authored by Ngô Đức Anh's avatar Ngô Đức Anh Committed by GitHub

Fix(typedRoutes): fixed StaticRoutes and DynamicRoutes being empty causing invalid syntax (#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)
parent 844776ef
...@@ -196,7 +196,6 @@ function createRouteDefinitions( ...@@ -196,7 +196,6 @@ function createRouteDefinitions(
} }
} }
const fallback = !edgeRoutes.length && !nodeRoutes.length ? 'string' : ''
const routes = [...edgeRoutes, ...nodeRoutes, ...extraRoutes] const routes = [...edgeRoutes, ...nodeRoutes, ...extraRoutes]
// By exposing the static route types separately as string literals, // By exposing the static route types separately as string literals,
...@@ -267,10 +266,12 @@ declare namespace __next_route_internal_types__ { ...@@ -267,10 +266,12 @@ declare namespace __next_route_internal_types__ {
type OptionalCatchAllSlug<S extends string> = type OptionalCatchAllSlug<S extends string> =
S extends \`\${string}\${SearchOrHash}\` ? never : S S extends \`\${string}\${SearchOrHash}\` ? never : S
type StaticRoutes = ${staticRouteTypes} type StaticRoutes = ${staticRouteTypes || 'string'}
type DynamicRoutes<T extends string = string> = ${dynamicRouteTypes} type DynamicRoutes<T extends string = string> = ${
dynamicRouteTypes || 'string'
}
type RouteImpl<T> = ${fallback} type RouteImpl<T> =
| StaticRoutes | StaticRoutes
| \`\${StaticRoutes}\${Suffix}\` | \`\${StaticRoutes}\${Suffix}\`
| (T extends \`\${DynamicRoutes<infer _>}\${Suffix}\` ? T : never) | (T extends \`\${DynamicRoutes<infer _>}\${Suffix}\` ? T : never)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment