Skip to content

Commit

Permalink
fix(typed-routes): Fix route type fallback (#73271)
Browse files Browse the repository at this point in the history
### What?

This PR updates the fallback type for typed routes to match the one in
https://github.com/vercel/next.js/blob/canary/packages/next/src/types.ts#L58.

### Why?

During builds, the `Route` type is initialized as the fallback type
before being populated by the routes. This causes temporary type
warnings in the project, since a route like `"" | Route` becomes `"" |
string` which can raise an ts-eslint error like `"" is overridden by
string in this union type`.
This becomes a problem in both failed builds, and in CI where a linter
and a build can run in parallel. Updating the type to match the stub
type fixes the issue.

Co-authored-by: Sam Ko <[email protected]>
Co-authored-by: JJ Kasper <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent b9fd422 commit 91065e3
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ function createRouteDefinitions() {
dynamicRouteTypes += pluginState.routeTypes[type].dynamic
}

// If both StaticRoutes and DynamicRoutes are empty, fallback to type 'string'.
// If both StaticRoutes and DynamicRoutes are empty, fallback to type 'string & {}'.
const routeTypesFallback =
!staticRouteTypes && !dynamicRouteTypes ? 'string' : ''
!staticRouteTypes && !dynamicRouteTypes ? 'string & {}' : ''

return `// Type definitions for Next.js routes
Expand Down

0 comments on commit 91065e3

Please sign in to comment.