Unverified Commit 1a406512 authored by Shu Ding's avatar Shu Ding Committed by GitHub

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
parent 33b8e615
......@@ -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<infer _>}\${Suffix}\` ? T : never)
`
......
......@@ -62,6 +62,11 @@ export default function page() {
<Link href="/redirect/v1/guides/x/page">test</Link>
<Link href="/redirect/guides/x/page">test</Link>
<Link href={new URL('/about')}>test</Link>
<Link href="https://nextjs.org">test</Link>
<Link href="http://nextjs.org">test</Link>
<Link href="#id">test</Link>
<Link href="?page=1">test</Link>
<Link href="mailto:foo@example.com">test</Link>
</>
)
......
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