Skip to content

Commit

Permalink
Update types for with-router (#7106)
Browse files Browse the repository at this point in the history
* Updated declarations for with-router
  • Loading branch information
Luis Fernando Alvarez D authored Apr 22, 2019
1 parent baabfbd commit db5b3dc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/next/client/with-router.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import React from 'react'
import PropTypes from 'prop-types'
import { NextComponentType, IContext } from 'next-server/dist/lib/utils'
import { IPublicRouterInstance } from './router';

export default function withRouter(ComposedComponent: React.ComponentType<any> & {getInitialProps?: any}) {
class WithRouteWrapper extends React.Component {
export type WithRouterProps = {
router: IPublicRouterInstance,
}

export type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>

export default function withRouter<P extends WithRouterProps, C = IContext>(ComposedComponent: NextComponentType<C, any, P>): React.ComponentClass<ExcludeRouterProps<P>> {
class WithRouteWrapper extends React.Component<ExcludeRouterProps<P>> {
static displayName?: string
static getInitialProps?: any
static contextTypes = {
router: PropTypes.object,
}

context!: WithRouterProps

render() {
return <ComposedComponent
router={this.context.router}
{...this.props}
{...this.props as any}
/>
}
}
Expand Down

0 comments on commit db5b3dc

Please sign in to comment.