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
This commit is contained in:
parent
33b8e6157f
commit
1a40651267
2 changed files with 8 additions and 0 deletions
|
@ -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>
|
||||
</>
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue