Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special route types to the link type declaration #50066

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function createRouteDefinitions() {
*/
declare namespace __next_route_internal_types__ {
type SearchOrHash = \`?\${string}\` | \`#\${string}\`
type WithProtocol = \`\${string}:\${string}\`

type Suffix = '' | SearchOrHash

Expand Down Expand Up @@ -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)
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
</>
)

Expand Down