solid-router icon indicating copy to clipboard operation
solid-router copied to clipboard

Allow typing the `data` property for `RouteDataFuncArgs`

Open ghalle opened this issue 3 years ago • 0 comments

This will allow to have full type checking for routeData functions using the data provided by another routeData function.

import { routeData as parentRouteData } from "../__index"

export function routeData(args: RouteDataFuncArgs<typeof parentRouteData>) {
  return createResource(
    () => args.data.user[0](),
    (user) => {}
  )
}

In the example above args.data is now fully typed instead of being unknown

Small breaking change RouteDataFunc now has 2 generic parameters the first one being the one passed to RouteDataFuncArgs where as it was previously the return type, the return type is now the second argument.

Although I would generally recommend not using RouteDataFunc so you can have the return type inferred like in the example above, I still modified it for people that might want to use it.

ghalle avatar Aug 03 '22 18:08 ghalle