diff --git a/packages/manager/src/routes/utils.test.tsx b/packages/manager/src/routes/utils.test.tsx index 27f16d1a16c..fb15b18108d 100644 --- a/packages/manager/src/routes/utils.test.tsx +++ b/packages/manager/src/routes/utils.test.tsx @@ -91,6 +91,7 @@ describe('strictLazyRouteComponent', () => { Promise.resolve({ notAComponent: 'string' }) ); + // @ts-expect-error - forcing the wrong type const result = strictLazyRouteComponent(mockImporter, 'notAComponent'); await expect((result as any)()).rejects.toThrow( 'Export "notAComponent" is not a valid React component' diff --git a/packages/manager/src/routes/utils.ts b/packages/manager/src/routes/utils.ts index 8441670b8e3..fdd831b0b15 100644 --- a/packages/manager/src/routes/utils.ts +++ b/packages/manager/src/routes/utils.ts @@ -1,8 +1,6 @@ import { lazyRouteComponent } from '@tanstack/react-router'; -import type { ComponentType } from 'react'; - -type AnyModule = { [key: string]: any }; +type AnyModule = { [key: string]: React.ComponentType }; /** * This function is a wrapper around lazyRouteComponent that ensures the @@ -12,7 +10,7 @@ type AnyModule = { [key: string]: any }; * By using a function overload we do just that. */ export function strictLazyRouteComponent< - T extends { default: ComponentType } + T extends { default: React.ComponentType } >(importer: () => Promise): ReturnType; export function strictLazyRouteComponent< T extends AnyModule, @@ -27,11 +25,11 @@ export function strictLazyRouteComponent( ): ReturnType { return lazyRouteComponent(() => importer().then((module) => { - let component: ComponentType; + let component: React.ComponentType; if (exportName) { if (exportName in module) { - component = module[exportName] as ComponentType; + component = module[exportName] as React.ComponentType; } else { throw new Error(`Export "${exportName}" not found in module`); }