Repository: tatethurston/nextjs-routes (ts)

Issue:
Catch-all routes aren't generated right when the name isn't a valid JS identifier but is a valid NextJS route
If I have an route which catches all subpaths such as `"/api/as-api/[...as-proxy]"` the generated route is `{ pathname: "/api/as-api/[...as-proxy]"; query: Query<{ as-proxy: string[] }> }`. Notice that there is a key, `as-proxy`, which is missing quotes to allow it to be a valid object key. 

Using `v0.0.18`

Pull request:
quote query segments
fix #49

Patch:
diff --git a/examples/src-pages/nextjs-routes.d.ts b/examples/src-pages/nextjs-routes.d.ts
index 8da5775..aea5095 100644
--- a/examples/src-pages/nextjs-routes.d.ts
+++ b/examples/src-pages/nextjs-routes.d.ts
@@ -6,8 +6,8 @@
 declare module "nextjs-routes" {
   export type Route =
     | { pathname: "/api/hello"; query?: Query | undefined }
-    | { pathname: "/bars/[bar]"; query: Query<{ bar: string }> }
-    | { pathname: "/foos/[foo]"; query: Query<{ foo: string }> }
+    | { pathname: "/bars/[bar]"; query: Query<{ "bar": string }> }
+    | { pathname: "/foos/[foo]"; query: Query<{ "foo": string }> }
     | { pathname: "/"; query?: Query | undefined };
 
   type Query<Params = {}> = Params & { [key: string]: string | string[] | undefined };
diff --git a/examples/typescript/nextjs-routes.d.ts b/examples/typescript/nextjs-routes.d.ts
index 8da5775..aea5095 100644
--- a/examples/typescript/nextjs-routes.d.ts
+++ b/examples/typescript/nextjs-routes.d.ts
@@ -6,8 +6,8 @@
 declare module "nextjs-routes" {
   export type Route =
     | { pathname: "/api/hello"; query?: Query | undefined }
-    | { pathname: "/bars/[bar]"; query: Query<{ bar: string }> }
-    | { pathname: "/foos/[foo]"; query: Query<{ foo: string }> }
+    | { pathname: "/bars/[bar]"; query: Query<{ "bar": string }> }
+    | { pathname: "/foos/[foo]"; query: Query<{ "foo": string }> }
     | { pathname: "/"; query?: Query | undefined };
 
   type Query<Params = {}> = Params & { [key: string]: string | string[] | undefined };
diff --git a/src/core.ts b/src/core.ts
index 16d2778..20f0b1f 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -66,14 +66,14 @@ function getQueryInterface(
       switch (value) {
         case "dynamic": {
           requiredKeys += 1;
-          return `${key}: string`;
+          return `"${key}": string`;
         }
         case "catch-all": {
           requiredKeys += 1;
-          return `${key}: string[]`;
+          return `"${key}": string[]`;
         }
         case "optional-catch-all": {
-          return `${key}?: string[] | undefined`;
+          return `"${key}"?: string[] | undefined`;
         }
         // istanbul ignore next
         default: {


Test patch:
diff --git a/e2e/nextjs-routes.d.ts b/e2e/nextjs-routes.d.ts
index 1779d83..7aa68f5 100644
--- a/e2e/nextjs-routes.d.ts
+++ b/e2e/nextjs-routes.d.ts
@@ -5,7 +5,7 @@
 // prettier-ignore
 declare module "nextjs-routes" {
   export type Route =
-    | { pathname: "/foos/[foo]"; query: Query<{ foo: string }> }
+    | { pathname: "/foos/[foo]"; query: Query<{ "foo": string }> }
     | { pathname: "/"; query?: Query | undefined };
 
   type Query<Params = {}> = Params & { [key: string]: string | string[] | undefined };
diff --git a/src/__snapshots__/core.test.ts.snap b/src/__snapshots__/core.test.ts.snap
index e5c4ce0..d7158ad 100644
--- a/src/__snapshots__/core.test.ts.snap
+++ b/src/__snapshots__/core.test.ts.snap
@@ -97,21 +97,21 @@ Array [
 declare module \\"nextjs-routes\\" {
   export type Route =
     | { pathname: \\"/404\\"; query?: Query | undefined }
-    | { pathname: \\"/[foo]\\"; query: Query<{ foo: string }> }
-    | { pathname: \\"/[foo]/[bar]/[baz]\\"; query: Query<{ foo: string; bar: string; baz: string }> }
-    | { pathname: \\"/[foo]/bar/[baz]\\"; query: Query<{ foo: string; baz: string }> }
-    | { pathname: \\"/[foo]/bar/[baz]/foo/[bar]\\"; query: Query<{ foo: string; baz: string; bar: string }> }
-    | { pathname: \\"/[foo]/baz\\"; query: Query<{ foo: string }> }
+    | { pathname: \\"/[foo]\\"; query: Query<{ \\"foo\\": string }> }
+    | { pathname: \\"/[foo]/[bar]/[baz]\\"; query: Query<{ \\"foo\\": string; \\"bar\\": string; \\"baz\\": string }> }
+    | { pathname: \\"/[foo]/bar/[baz]\\"; query: Query<{ \\"foo\\": string; \\"baz\\": string }> }
+    | { pathname: \\"/[foo]/bar/[baz]/foo/[bar]\\"; query: Query<{ \\"foo\\": string; \\"baz\\": string; \\"bar\\": string }> }
+    | { pathname: \\"/[foo]/baz\\"; query: Query<{ \\"foo\\": string }> }
     | { pathname: \\"/_debug\\"; query?: Query | undefined }
     | { pathname: \\"/_debug/health-check\\"; query?: Query | undefined }
     | { pathname: \\"/api/[[...segments]]\\"; query?: Query | undefined }
-    | { pathname: \\"/api/[...segments]\\"; query: Query<{ segments: string[] }> }
+    | { pathname: \\"/api/[...segments]\\"; query: Query<{ \\"segments\\": string[] }> }
     | { pathname: \\"/api/bar\\"; query?: Query | undefined }
-    | { pathname: \\"/foo/[slug]\\"; query: Query<{ slug: string }> }
+    | { pathname: \\"/foo/[slug]\\"; query: Query<{ \\"slug\\": string }> }
     | { pathname: \\"/\\"; query?: Query | undefined }
     | { pathname: \\"/not-found\\"; query?: Query | undefined }
-    | { pathname: \\"/settings/bars/[bar]\\"; query: Query<{ bar: string }> }
-    | { pathname: \\"/settings/bars/[bar]/baz\\"; query: Query<{ bar: string }> }
+    | { pathname: \\"/settings/bars/[bar]\\"; query: Query<{ \\"bar\\": string }> }
+    | { pathname: \\"/settings/bars/[bar]/baz\\"; query: Query<{ \\"bar\\": string }> }
     | { pathname: \\"/settings/foo\\"; query?: Query | undefined }
     | { pathname: \\"/settings\\"; query?: Query | undefined };