Closed denbon05 closed 7 months ago
It is supposed to be the type of the RouteData function which I admit in this case isn't very convenient but is more so in file system routed systems.
Ex.
import type { BlockData } from "./block.data.ts"
const BlockMore: Component = () => {
const block = useRouteData<typeof BlockData>();
return <div>{JSON.stringify(block(), null, 2)}</div>; // in fact it's callable
};
export default BlockMore;
Docs need to be clearer about this.
@ryansolid in that case I'm facing 'block()' is of type 'unknown'
it seems we still have to use as
like here:
const blockSrc = useRouteData<typeof BlockData>() as Resource<ETHBlock>;
This is related to the previous version of the router. TS issues with useRouteData
was one of the motivations of changing it. Closing as addressing any bug here is no longer planned.
Describe the bug
block.data.ts
BlockMore.tsx
Your Example Website or App
https://github.com/denbon05/blockexplorer/blob/main/src/pages/BlockAbout.tsx
Steps to Reproduce the Bug or Issue
https://docs.solidjs.com/guides/how-to-guides/routing-in-solid/solid-router#data-functions Follow the documentation to face this bug.
Expected behavior
The router data function should infer the appropriate type.
Screenshots or Videos
Called
block
result in browser:Platform
Additional context
No response