Skip to content

Commit

Permalink
fix(react-router): Failing with strictFunctionTypes (#38453)
Browse files Browse the repository at this point in the history
* Revert implementation of #38326

* Skip ComponentType test which only fails starting with 3.6
  • Loading branch information
eps1lon authored and orta committed Sep 18, 2019
1 parent 916f609 commit ad1ea50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 3 additions & 7 deletions types/react-router/index.d.ts
Expand Up @@ -143,12 +143,8 @@ export interface WithRouterStatics<C extends React.ComponentType<any>> {
// they are decorating. Due to this, if you are using @withRouter decorator in your code,
// you will see a bunch of errors from TypeScript. The current workaround is to use withRouter() as a function call
// on a separate line instead of as a decorator.
export function withRouter<C extends React.ComponentType<RouteComponentProps>>(
component: C,
): React.ComponentClass<
Omit<React.ComponentProps<C>, keyof RouteComponentProps> & WithRouterProps<C>,
never
> &
WithRouterStatics<C>;
export function withRouter<P extends RouteComponentProps<any>, C extends React.ComponentType<P>>(
component: C & React.ComponentType<P>,
): React.ComponentClass<Omit<P, keyof RouteComponentProps<any>> & WithRouterProps<C>> & WithRouterStatics<C>;

export const __RouterContext: React.Context<RouteComponentProps>;
9 changes: 6 additions & 3 deletions types/react-router/test/WithRouter.tsx
Expand Up @@ -13,8 +13,6 @@ const FunctionComponent: React.FunctionComponent<TOwnProps> = props => (
<h2>Welcome {props.username}</h2>
);

declare const Component: React.ComponentType<TOwnProps>;

class ComponentClass extends React.Component<TOwnProps> {
render() {
return <h2>Welcome {this.props.username}</h2>;
Expand All @@ -23,10 +21,15 @@ class ComponentClass extends React.Component<TOwnProps> {

const WithRouterComponentFunction = withRouter(ComponentFunction);
const WithRouterFunctionComponent = withRouter(FunctionComponent);
const WithRouterComponent = withRouter(Component);
const WithRouterComponentClass = withRouter(ComponentClass);
WithRouterComponentClass.WrappedComponent; // $ExpectType typeof ComponentClass

// Fix introduced in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/38326
// caused more common use cases with `strictFunctionTypes` to fail
// declare const Component: React.ComponentType<TOwnProps>;
// $ExpectError ^3.6.3
// const WithRouterComponent = withRouter(Component);

const WithRouterTestFunction = () => (
<WithRouterComponentFunction username="John" />
);
Expand Down

0 comments on commit ad1ea50

Please sign in to comment.