Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for Route class are wrong #404

Open
thehappycoder opened this issue Jun 12, 2019 · 4 comments
Open

Types for Route class are wrong #404

thehappycoder opened this issue Jun 12, 2019 · 4 comments

Comments

@thehappycoder
Copy link

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 }) {
  }
}
@jquense
Copy link
Member

jquense commented Jun 12, 2019

Why can't you extend it?

@thehappycoder
Copy link
Author

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

  }
}

@taion
Copy link
Contributor

taion commented Jun 13, 2019

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 taion self-assigned this Jun 13, 2019
@taion
Copy link
Contributor

taion commented Nov 21, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants