From 91065e39283337790325785437d0a3239f3a0b80 Mon Sep 17 00:00:00 2001 From: Ali Tas Date: Wed, 18 Dec 2024 22:40:38 -0500 Subject: [PATCH] fix(typed-routes): Fix route type fallback (#73271) ### 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 Co-authored-by: JJ Kasper --- .../next/src/build/webpack/plugins/next-types-plugin/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts b/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts index 29ed3e36be8e4..389e37859883d 100644 --- a/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts +++ b/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts @@ -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