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

fix withRouter types #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

fix withRouter types #24

wants to merge 2 commits into from

Conversation

billyjs
Copy link

@billyjs billyjs commented Jun 12, 2020

This was previously merged into @atlaskit/router on atlassian-frontend for AKR-23 but didn't get migrated to RRR.

const Component = WrappedComponent as ComponentType<WithRouter & P>;
const ComponentWithRouter = (props: P) => (
const Component = WrappedComponent;
const ComponentWithRouter = (unknownProps: any) => (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is "unknown" necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's not

Copy link
Collaborator

@MonicaOlejniczak MonicaOlejniczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too fond of losing type information with the use of any and it should be resolved to ensure improved type safety.

const displayName = getWrappedComponentDisplayName(WrappedComponent);
const Component = WrappedComponent as ComponentType<WithRouter & P>;
const ComponentWithRouter = (props: P) => (
const Component = WrappedComponent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/nit May as well just renamed the WrappedComponent argument to Component?

const Component = WrappedComponent as ComponentType<WithRouter & P>;
const ComponentWithRouter = (props: P) => (
const Component = WrappedComponent;
const ComponentWithRouter = (props: any) => (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you use P anymore over any?

export type Route = {
path: string;
exact?: boolean;

/** The component to render on match, typed explicitly */
component: ComponentType<RouteContext>;
component: ComponentType<RouteComponentProps> | ComponentType<any>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just be made into an optional generic like in the withRouter case? This should only need to be supported for consumers that do not use the exported RouteComponent component, and I would avoid the use of any here as a result. The default prop type just just be RouteComponentProps for those using the route component.

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

Successfully merging this pull request may close these issues.

3 participants