found icon indicating copy to clipboard operation
found copied to clipboard

Types for Route class are wrong

Open thehappycoder opened this issue 6 years ago • 4 comments

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 }) {
  }
}

thehappycoder avatar Jun 12 '19 23:06 thehappycoder

Why can't you extend it?

jquense avatar Jun 12 '19 23:06 jquense

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) {

  }
}

thehappycoder avatar Jun 13 '19 07:06 thehappycoder

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?

taion avatar Jun 13 '19 16:06 taion

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.

taion avatar Nov 21 '19 01:11 taion