mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
fix(react-router): Failing with strictFunctionTypes (#38453)
* Revert implementation of #38326 * Skip ComponentType test which only fails starting with 3.6
This commit is contained in:
committed by
Orta
parent
916f609e21
commit
ad1ea50852
10
types/react-router/index.d.ts
vendored
10
types/react-router/index.d.ts
vendored
@@ -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>;
|
||||
|
||||
@@ -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>;
|
||||
@@ -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" />
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user