found
found copied to clipboard
Types for Route class are wrong
Types:
class Route extends React.Component<RouteProps> {}
Js code:
/**
* Convenience class for creating normal routes with JSX. When not using JSX,
* use a POJSO instead of this class.
*/
export default class Route {
constructor(props) {
Object.assign(this, props);
}
}
if (__DEV__) {
// Workaround to make React Proxy give me the original class, to allow
// makeRouteConfig to get the actual class, when using JSX for routes.
Route.prototype.isReactComponent = {};
}
Because of this, I can't extend this class:
class Foo extends Route {
render({ Component, props }) {
}
}
Why can't you extend it?
This is the message that I get when I try to extend it:
Property 'render' in type 'Foo' is not assignable to the same property in base type 'Route'.
Type '({ Component, props }: any) => void' is not assignable to type '() => ReactNode'.
class Foo extends Route {
render({Component, props}: any) {
}
}
Right, I see. If we define it as a component type, then things extending it can't nicely override render. Let's see what we can do – unless you want to take a stab at it?
Unfortunately, I can't find a way to fix this that both allows that override for <Route> and keeps it valid as a JSX constructor. I'll leave this open for now.