solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.15k stars 147 forks source link

fix(typescript): `RouteDataFuncArgs.data` incorrect type #263

Closed otonashixav closed 1 year ago

otonashixav commented 1 year ago

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:

  data: T extends RouteDataFunc<any> ? ReturnType<T> : T;