I have a component that wraps Router
and takes an additional props. I tried using PropsWithoutRef
in a way that's analogous to the use in this cheatsheet:
import React, { ComponentType, PropsWithoutRef } from 'react'
import { Route } from 'react-router'
type LayoutRouteProps = PropsWithoutRef<Route> & {
component: ComponentType,
};
const DashboardLayoutRoute = ({
component: Component,
...rest
}: LayoutRouteProps) => {
const render = (props: any)=> <Component {...props} />
return <Route {...rest} render={render} />
};
But it did no good. When I try to use DashboardLayoutRoute
and pass props relevant to Route
:
<DashboardLayoutRoute exact path='/' component={Home} />
I get
Error:(63, 39) TS2322: Type '{ exact: true; path: string; component: any; }' is not assignable to type 'IntrinsicAttributes & Route & { component: ComponentType<{}>; }'.
Property 'exact' does not exist on type 'IntrinsicAttributes & Route & { component: ComponentType<{}>; }'.
Error:(66, 39) TS2322: Type '{ path: string; component: any; }' is not assignable to type 'IntrinsicAttributes & Route & { component: ComponentType<{}>; }'.
Property 'path' does not exist on type 'IntrinsicAttributes & Route & { component: ComponentType<{}>; }'.
What's wrong with my code?