From f5092a943f6b88f065f0263d0f4dcb5c3b74be9d Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 23 May 2023 19:36:09 +0200 Subject: [PATCH] Add special route types to the link type declaration (#50066) This PR adds generated type definitions for `Link` hrefs with only search, hash or with a protocol. Closes #49825. fix NEXT-1203 --- packages/next/src/build/webpack/plugins/next-types-plugin.ts | 3 +++ test/integration/app-types/src/app/type-checks/link/page.tsx | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/packages/next/src/build/webpack/plugins/next-types-plugin.ts b/packages/next/src/build/webpack/plugins/next-types-plugin.ts index 07406afba98cf..81118585efaf8 100644 --- a/packages/next/src/build/webpack/plugins/next-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/next-types-plugin.ts @@ -362,6 +362,7 @@ function createRouteDefinitions() { */ declare namespace __next_route_internal_types__ { type SearchOrHash = \`?\${string}\` | \`#\${string}\` + type WithProtocol = \`\${string}:\${string}\` type Suffix = '' | SearchOrHash @@ -394,6 +395,8 @@ declare namespace __next_route_internal_types__ { // This keeps autocompletion working for static routes. '| StaticRoutes' } + | SearchOrHash + | WithProtocol | \`\${StaticRoutes}\${SearchOrHash}\` | (T extends \`\${DynamicRoutes}\${Suffix}\` ? T : never) ` diff --git a/test/integration/app-types/src/app/type-checks/link/page.tsx b/test/integration/app-types/src/app/type-checks/link/page.tsx index 2e07b9cecd4e1..6c9fa7e5f2c88 100644 --- a/test/integration/app-types/src/app/type-checks/link/page.tsx +++ b/test/integration/app-types/src/app/type-checks/link/page.tsx @@ -62,6 +62,11 @@ export default function page() { test test test + test + test + test + test + test )