Skip to content

Commit d0695a7

Browse files
authored
fix(typescript): RouteDataFuncArgs.data incorrect type (#263)
Using `RouteDataFunc` without specifying any generic types results in `RouteDataFunc<unknown, unknown>`, which `RouteDataFunc<NotUnknown, unknown>` does not extend. See https://stackblitz.com/edit/solid-ssr-vite-pcbdkr?file=tsconfig.json,src%2Froutes%2Findex.tsx: ``` Expected 1 arguments, but got 0.(2554) index.tsx(7, 25): An argument for 'args' was not provided. ``` Since `(args: RouteDataArgs<typeof routeData>) => (() => undefined) | (() => string)` does not extend `RouteDataFunc<unknown, unknown>`, the type is not `ReturnType<T>` but `T`. This change makes it so that that case is properly handled and typed. I avoided using `any` but the change would otherwise be equivalent to: ```ts data: T extends RouteDataFunc<any> ? ReturnType<T> : T; ```
1 parent b2b1313 commit d0695a7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export interface RouterIntegration {
4545
}
4646

4747
export interface RouteDataFuncArgs<T = unknown> {
48-
data: T extends RouteDataFunc ? ReturnType<T> : T;
48+
data: T extends RouteDataFunc<infer _, infer R> ? R : T;
4949
params: Params;
5050
location: Location;
5151
navigate: Navigator;

0 commit comments

Comments
 (0)