From 0248eccf4248520a6380456c99f33d5fc76a465c Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Sat, 30 Dec 2023 14:03:30 -0600 Subject: [PATCH] Fix the type error with possibly infinite deep --- src/utilities/createRouteMethods.spec.ts | 8 ++++---- src/utilities/createRouteMethods.ts | 6 +++--- src/utilities/createRouter.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utilities/createRouteMethods.spec.ts b/src/utilities/createRouteMethods.spec.ts index 490bf706..ef0fe3b7 100644 --- a/src/utilities/createRouteMethods.spec.ts +++ b/src/utilities/createRouteMethods.spec.ts @@ -18,7 +18,7 @@ describe('createRouteMethods', () => { ] as const satisfies Routes const resolved = resolveRoutes(routes) - const response = createRouteMethods(resolved) + const response = createRouteMethods(resolved) expect(response.parent).toBeTypeOf('function') }) @@ -34,7 +34,7 @@ describe('createRouteMethods', () => { ] as const satisfies Routes const resolved = resolveRoutes(routes) - const response = createRouteMethods(resolved) + const response = createRouteMethods(resolved) expect(response).toMatchObject({}) }) @@ -60,7 +60,7 @@ describe('createRouteMethods', () => { ] as const satisfies Routes const resolved = resolveRoutes(routes) - const response = createRouteMethods(resolved) + const response = createRouteMethods(resolved) expect(response.parent.child).toBeDefined() @@ -91,7 +91,7 @@ describe('createRouteMethods', () => { ] as const satisfies Routes const resolved = resolveRoutes(routes) - const response = createRouteMethods(resolved) + const response = createRouteMethods(resolved) expect(response.parent).toBeTypeOf('function') expect(response.parent.child).toBeTypeOf('function') diff --git a/src/utilities/createRouteMethods.ts b/src/utilities/createRouteMethods.ts index 5b631dfa..510729b3 100644 --- a/src/utilities/createRouteMethods.ts +++ b/src/utilities/createRouteMethods.ts @@ -1,4 +1,4 @@ -import { Resolved, Route, RouteMethodResponse, isPublicRoute } from '@/types' +import { Resolved, Route, RouteMethodResponse, RouteMethods, Routes, isPublicRoute } from '@/types' import { assembleUrl } from '@/utilities/urlAssembly' type NonCallableNode = Record @@ -7,14 +7,14 @@ type CallableNode = NonCallableNode & { } type Node = CallableNode | NonCallableNode -export function createRouteMethods(routes: Resolved[]): Record { +export function createRouteMethods(routes: Resolved[]): RouteMethods { const methods: Record = {} routes.forEach(route => { traverseParents(route, methods) }) - return methods + return methods as unknown as RouteMethods } function traverseParents(route: Resolved, currentLevel: Record): Record { diff --git a/src/utilities/createRouter.ts b/src/utilities/createRouter.ts index d832de47..a1427d84 100644 --- a/src/utilities/createRouter.ts +++ b/src/utilities/createRouter.ts @@ -48,7 +48,7 @@ export function createRouter(routes: T): Router { } const router = { - routes: createRouteMethods(resolved) as RouteMethods, + routes: createRouteMethods(resolved), push, replace, forward,