2019-04-17 13:51:52 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import { Omit } from '../_util/type';
|
2019-04-23 11:23:20 +08:00
|
|
|
import { WrappedFormInternalProps } from './Form';
|
2019-04-17 13:51:52 +08:00
|
|
|
|
2019-05-09 19:28:50 +08:00
|
|
|
// Heavily copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/hoist-non-react-statics/index.d.ts
|
|
|
|
// tslint:disable-next-line:class-name
|
|
|
|
interface REACT_STATICS {
|
|
|
|
childContextTypes: true;
|
|
|
|
contextType: true;
|
|
|
|
contextTypes: true;
|
|
|
|
defaultProps: true;
|
|
|
|
displayName: true;
|
|
|
|
getDefaultProps: true;
|
|
|
|
getDerivedStateFromError: true;
|
|
|
|
getDerivedStateFromProps: true;
|
|
|
|
mixins: true;
|
|
|
|
propTypes: true;
|
|
|
|
type: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line:class-name
|
|
|
|
interface KNOWN_STATICS {
|
|
|
|
name: true;
|
|
|
|
length: true;
|
|
|
|
prototype: true;
|
|
|
|
caller: true;
|
|
|
|
callee: true;
|
|
|
|
arguments: true;
|
|
|
|
arity: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line:class-name
|
|
|
|
interface MEMO_STATICS {
|
|
|
|
$$typeof: true;
|
|
|
|
compare: true;
|
|
|
|
defaultProps: true;
|
|
|
|
displayName: true;
|
|
|
|
propTypes: true;
|
|
|
|
type: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line:class-name
|
|
|
|
interface FORWARD_REF_STATICS {
|
|
|
|
$$typeof: true;
|
|
|
|
render: true;
|
|
|
|
defaultProps: true;
|
|
|
|
displayName: true;
|
|
|
|
propTypes: true;
|
|
|
|
}
|
|
|
|
|
|
|
|
type NonReactStatics<
|
|
|
|
S extends React.ComponentType<any>,
|
|
|
|
C extends {
|
|
|
|
[key: string]: true;
|
|
|
|
} = {}
|
|
|
|
> = {
|
|
|
|
[key in Exclude<
|
|
|
|
keyof S,
|
|
|
|
S extends React.MemoExoticComponent<any>
|
|
|
|
? keyof MEMO_STATICS | keyof C
|
|
|
|
: S extends React.ForwardRefExoticComponent<any>
|
|
|
|
? keyof FORWARD_REF_STATICS | keyof C
|
|
|
|
: keyof REACT_STATICS | keyof KNOWN_STATICS | keyof C
|
2019-06-19 19:09:08 +08:00
|
|
|
>]: S[key];
|
2019-05-09 19:28:50 +08:00
|
|
|
};
|
|
|
|
|
2019-04-17 13:51:52 +08:00
|
|
|
// Copy from @types/react-redux https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-redux/index.d.ts
|
2019-04-23 11:23:20 +08:00
|
|
|
export type Matching<InjectedProps, DecorationTargetProps> = {
|
|
|
|
[P in keyof DecorationTargetProps]: P extends keyof InjectedProps
|
2019-05-07 14:57:32 +08:00
|
|
|
? InjectedProps[P] extends DecorationTargetProps[P]
|
|
|
|
? DecorationTargetProps[P]
|
|
|
|
: InjectedProps[P]
|
2019-06-19 19:09:08 +08:00
|
|
|
: DecorationTargetProps[P];
|
2019-04-23 11:23:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export type GetProps<C> = C extends React.ComponentType<infer P> ? P : never;
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
export type ConnectedComponentClass<C extends React.ComponentType<any>, P> = React.ComponentClass<
|
|
|
|
JSX.LibraryManagedAttributes<C, P>
|
|
|
|
> &
|
2019-05-09 19:28:50 +08:00
|
|
|
NonReactStatics<C> & {
|
2019-05-07 14:57:32 +08:00
|
|
|
WrappedComponent: C;
|
|
|
|
};
|
2019-04-17 13:51:52 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
export type FormWrappedProps<TOwnProps extends WrappedFormInternalProps> = <
|
|
|
|
C extends React.ComponentType<Matching<TOwnProps, GetProps<C>>>
|
|
|
|
>(
|
|
|
|
component: C,
|
|
|
|
) => ConnectedComponentClass<C, Omit<TOwnProps, keyof WrappedFormInternalProps>>;
|