Closed bezenson closed 4 months ago
Of course I can make props optional, but this is a hack, not a solution
Not really, no. This is an inherent limitation of TypeScript and type safety in general. AFAIK, TS offers no mechanism to override or extend the props of child nodes. If you say ProductProps
takes specific props, then they need to be supplied or marked as optional.
However, there's sort of a workaround in the Route
component, if you want to appease TS:
import { Route, Router } from 'preact-router';
function App() {
return (
<Router>
<Route path={routePath('/:id?')} component={Products} />
<Route path={routePath('/cart')} component={Cart} />
</Router>
);
}
This will get rid of the error.
@rschristian It looks like a solution. Thank you. Will be good to add it to README.MD
PRs welcome
@rschristian Here's a PR: https://github.com/preactjs/preact-router/pull/465
I created a router in a way that is explained in the description:
Products
component hasmatches
,path
,url
props inside.When I am describing them in interface - I am getting error in root tsx file:
Of course I can make props optional, but this is a hack, not a solution. When I render component inside
<Route>
it will always have this props.