-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: master
Are you sure you want to change the base?
Conversation
const Component = WrappedComponent as ComponentType<WithRouter & P>; | ||
const ComponentWithRouter = (props: P) => ( | ||
const Component = WrappedComponent; | ||
const ComponentWithRouter = (unknownProps: any) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is "unknown" necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's not
There was a problem hiding this 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; |
There was a problem hiding this comment.
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) => ( |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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.
This was previously merged into @atlaskit/router on atlassian-frontend for AKR-23 but didn't get migrated to RRR.