Created
February 27, 2023 17:28
-
-
Save almeidx/e1298bdd6d7f80b6102f714913e684d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'next' { | |
export * from 'next/types/index.d.ts'; | |
type SearchOrHash = `?${string}` | `#${string}` | |
type Suffix = "" | SearchOrHash | |
type SafeSlug<S extends string> = | |
S extends `${string}/${string}` | |
? never | |
: S extends `${string}${SearchOrHash}` | |
? never | |
: S extends '' | |
? never | |
: S | |
type CatchAllSlug<S extends string> = | |
S extends `${string}${SearchOrHash}` | |
? never | |
: S extends '' | |
? never | |
: S | |
type OptionalCatchAllSlug<S extends string> = | |
S extends `${string}${SearchOrHash}` | |
? never | |
: S | |
export type Route<T extends string = string> = | |
| `/privacy${Suffix}` | |
| `/terms${Suffix}` | |
| `/levels/calculator${Suffix}` | |
| `/${Suffix}` | |
| `/status${Suffix}` | |
} | |
declare module 'next/link' { | |
import type { Route } from 'next' | |
import type { LinkProps as OriginalLinkProps } from 'next/dist/client/link' | |
import type { AnchorHTMLAttributes } from 'react' | |
import type { UrlObject } from 'url' | |
type LinkRestProps = Omit<Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof OriginalLinkProps> & OriginalLinkProps, 'href'>; | |
// If the href prop can be a Route type with an infer-able S, it's valid. | |
type HrefProp<T> = T extends (Route<infer S> | UrlObject) ? { | |
/** | |
* The path or URL to navigate to. This is the only required prop. It can also be an object. | |
* | |
* https://nextjs.org/docs/api-reference/next/link | |
*/ | |
href: T | |
} : { | |
/** | |
* The path or URL to navigate to. This is the only required prop. It can also be an object. | |
* | |
* https://nextjs.org/docs/api-reference/next/link | |
*/ | |
href: never | |
} | |
export type LinkProps<T> = LinkRestProps & HrefProp<T> | |
export default function Link<RouteType>(props: LinkProps<RouteType>): JSX.Element | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment