Repository: tatethurston/nextjs-routes
Pull request #104 (2022-11-22 19:59:32)

enable static hrefs for LinkProps


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65fbf94..5e9c2bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
 # Changelog
 
+## 1.0.4
+
+- `LinkProps` now accept path strings for static routes:
+
+  ```tsx
+  import { LinkProps } from "next/link";
+  // previously this would error
+  const props: LinkProps = { href: "/foo" };
+  ```
+
 ## 1.0.3
 
 - The `Route` type now includes `hash`. This enables the following:
diff --git a/README.md b/README.md
index 5c82723..c5ee5bb 100644
--- a/README.md
+++ b/README.md
@@ -241,6 +241,8 @@ const withRoutes = require("nextjs-routes/config")({
 
 PR's and issues welcomed! For more guidance check out [CONTRIBUTING.md](https://github.com/tatethurston/nextjs-routes/blob/main/CONTRIBUTING.md)
 
+Are you interested in bringing a `nextjs-routes` like experience to another framework? [Open an issue](https://github.com/tatethurston/nextjs-routes/issues/new) and let's collaborate.
+
 ## Licensing 📃
 
 See the project's [MIT License](https://github.com/tatethurston/nextjs-routes/blob/main/LICENSE).
diff --git a/examples/intl/nextjs-routes.d.ts b/examples/intl/nextjs-routes.d.ts
index e7edc61..ae34b94 100644
--- a/examples/intl/nextjs-routes.d.ts
+++ b/examples/intl/nextjs-routes.d.ts
@@ -49,15 +49,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
diff --git a/examples/typescript/types/nextjs-routes.d.ts b/examples/typescript/types/nextjs-routes.d.ts
index 28c7406..57ff7a1 100644
--- a/examples/typescript/types/nextjs-routes.d.ts
+++ b/examples/typescript/types/nextjs-routes.d.ts
@@ -48,15 +48,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
diff --git a/public.package.json b/public.package.json
index 04ddd47..869e92d 100644
--- a/public.package.json
+++ b/public.package.json
@@ -1,6 +1,6 @@
 {
   "name": "nextjs-routes",
-  "version": "1.0.3",
+  "version": "1.0.4",
   "description": "Type safe routing for Next.js",
   "license": "MIT",
   "author": "Tate <tatethurston@gmail.com>",
diff --git a/src/core.ts b/src/core.ts
index a0dca71..d4cbef4 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -141,15 +141,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;


Test patch:
diff --git a/e2e/nextjs-routes.d.ts b/e2e/nextjs-routes.d.ts
index c329b5c..c0c9466 100644
--- a/e2e/nextjs-routes.d.ts
+++ b/e2e/nextjs-routes.d.ts
@@ -47,15 +47,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
diff --git a/e2e/package-lock.json b/e2e/package-lock.json
index c9ef50f..42e0973 100644
--- a/e2e/package-lock.json
+++ b/e2e/package-lock.json
@@ -20,7 +20,7 @@
     },
     "../dist": {
       "name": "nextjs-routes",
-      "version": "1.0.2",
+      "version": "1.0.4",
       "dev": true,
       "license": "MIT",
       "dependencies": {
diff --git a/e2e/typetest.tsx b/e2e/typetest.tsx
index 20ac09f..e572490 100644
--- a/e2e/typetest.tsx
+++ b/e2e/typetest.tsx
@@ -64,9 +64,9 @@ function expectType<T>(_value: T) {}
 // LinkProps
 
 // ensure LinkProps is our LinkProps, not the untyped one
-
 expectType<LinkProps["href"]>({ pathname: "/" });
-
+// static route
+expectType<LinkProps["href"]>("/");
 // @ts-expect-error invalid pathname
 expectType<LinkProps["href"]>({ pathname: "/invalid" });
 
diff --git a/src/__snapshots__/core.test.ts.snap b/src/__snapshots__/core.test.ts.snap
index cfc1646..9121195 100644
--- a/src/__snapshots__/core.test.ts.snap
+++ b/src/__snapshots__/core.test.ts.snap
@@ -52,15 +52,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -213,15 +215,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -388,15 +392,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -548,15 +554,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -706,15 +714,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -864,15 +874,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -1022,15 +1034,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -1180,15 +1194,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;
@@ -1355,15 +1371,17 @@ declare module "next/link" {
   import type {
     AnchorHTMLAttributes,
     DetailedReactHTMLElement,
-    PropsWithChildren,
     MouseEventHandler,
+    PropsWithChildren,
   } from "react";
   export * from "next/dist/client/link";
 
   type Query = { query?: { [key: string]: string | string[] | undefined } };
   type StaticRoute = Exclude<Route, { query: any }>["pathname"];
 
-  export interface LinkProps<Href extends Route | Query = Route | Query>
+  export interface LinkProps<
+    Href extends Route | StaticRoute | Query = Route | StaticRoute | Query
+  >
     extends Omit<NextLinkProps, "href" | "locale">,
       AnchorHTMLAttributes<HTMLAnchorElement> {
     href: Href;