From 6b0e1103260c8fffbbc5ef284ce6d518d6238960 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 23 Jun 2023 14:25:36 -0400 Subject: [PATCH 1/2] Enahnce route.lazy return type --- .changeset/route-lazy-type.md | 5 +++++ packages/router/utils.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/route-lazy-type.md diff --git a/.changeset/route-lazy-type.md b/.changeset/route-lazy-type.md new file mode 100644 index 0000000000..10ede70426 --- /dev/null +++ b/.changeset/route-lazy-type.md @@ -0,0 +1,5 @@ +--- +"@remix-run/router": patch +--- + +Enhance the return type of `Route.lazy` to prohibit returning an empty object diff --git a/packages/router/utils.ts b/packages/router/utils.ts index 6c7796ed3f..14b4126d6a 100644 --- a/packages/router/utils.ts +++ b/packages/router/utils.ts @@ -239,12 +239,19 @@ export const immutableRouteKeys = new Set([ "children", ]); +type RequireOne = Exclude< + { + [K in keyof T]: K extends Key ? Omit & Required> : never; + }[keyof T], + undefined +>; + /** * lazy() function to load a route definition, which can add non-matching * related properties to a route */ export interface LazyRouteFunction { - (): Promise>; + (): Promise>>; } /** From 5a4df4c3ed062b54e68e286a72ed6420d5fe71c0 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Fri, 23 Jun 2023 14:53:18 -0400 Subject: [PATCH 2/2] Fix upstream type in RR --- packages/react-router/lib/context.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/react-router/lib/context.ts b/packages/react-router/lib/context.ts index 8e5951154c..0cf6b94208 100644 --- a/packages/react-router/lib/context.ts +++ b/packages/react-router/lib/context.ts @@ -10,7 +10,6 @@ import type { StaticHandlerContext, To, TrackedPromise, - LazyRouteFunction, } from "@remix-run/router"; import type { Action as NavigationType } from "@remix-run/router"; @@ -31,7 +30,7 @@ export interface IndexRouteObject { errorElement?: React.ReactNode | null; Component?: React.ComponentType | null; ErrorBoundary?: React.ComponentType | null; - lazy?: LazyRouteFunction; + lazy?: AgnosticIndexRouteObject["lazy"]; } export interface NonIndexRouteObject { @@ -49,7 +48,7 @@ export interface NonIndexRouteObject { errorElement?: React.ReactNode | null; Component?: React.ComponentType | null; ErrorBoundary?: React.ComponentType | null; - lazy?: LazyRouteFunction; + lazy?: AgnosticNonIndexRouteObject["lazy"]; } export type RouteObject = IndexRouteObject | NonIndexRouteObject;