|
| 1 | +// flow-typed signature: 3010d1e44b78eedb9cf85c4f9af67238 |
| 2 | +// flow-typed version: a9e75cb9a5/hoist-non-react-statics_v3.x.x/flow_>=v0.84.x <=v0.102.x |
| 3 | + |
| 4 | +declare module 'hoist-non-react-statics' { |
| 5 | + /** |
| 6 | + * Inspired by DefinitelyTyped/types/hoist-non-react-statics/index.d.ts |
| 7 | + * |
| 8 | + * Unfortunately, unlike in TypeScript, current flow definitions for React does not allow us to tell whether |
| 9 | + * a React$ComponentType is “clean”, or had been the result of a call to React.memo or React.forwardRef. |
| 10 | + * Therefore we’ll only be able to precisely filter out statics that are common to all 3 cases, and will |
| 11 | + * have to live with maybes for everything else. This is not 100% precise, but is better than a blanket |
| 12 | + * $Shape call on the source component’s statics like what we were doing before in the v2.x.x defs. |
| 13 | + */ |
| 14 | + |
| 15 | + // declare type REACT_STATICS = { |
| 16 | + // childContextTypes: any, |
| 17 | + // contextType: any, |
| 18 | + // contextTypes: any, |
| 19 | + // defaultProps: any, |
| 20 | + // displayName: any, |
| 21 | + // getDefaultProps: any, |
| 22 | + // getDerivedStateFromError: any, |
| 23 | + // getDerivedStateFromProps: any, |
| 24 | + // mixins: any, |
| 25 | + // propTypes: any, |
| 26 | + // type: any, |
| 27 | + // ... |
| 28 | + // }; |
| 29 | + |
| 30 | + // declare type MEMO_STATICS = { |
| 31 | + // $$typeof: any, |
| 32 | + // compare: any, |
| 33 | + // defaultProps: any, |
| 34 | + // displayName: any, |
| 35 | + // propTypes: any, |
| 36 | + // type: any, |
| 37 | + // ... |
| 38 | + // }; |
| 39 | + |
| 40 | + // declare type FORWARD_REF_STATICS = { |
| 41 | + // $$typeof: any, |
| 42 | + // render: any, |
| 43 | + // defaultProps: any, |
| 44 | + // displayName: any, |
| 45 | + // propTypes: any, |
| 46 | + // ... |
| 47 | + // }; |
| 48 | + |
| 49 | + declare type REACT_STATICS = { |
| 50 | + // “Maybe” React statics |
| 51 | + $$typeof?: any, |
| 52 | + childContextTypes?: any, |
| 53 | + compare?: any, |
| 54 | + contextType?: any, |
| 55 | + contextTypes?: any, |
| 56 | + getDefaultProps?: any, |
| 57 | + getDerivedStateFromError?: any, |
| 58 | + getDerivedStateFromProps?: any, |
| 59 | + mixins?: any, |
| 60 | + render?: any, |
| 61 | + type?: any, |
| 62 | + // Common React statics |
| 63 | + defaultProps: any, |
| 64 | + displayName: any, |
| 65 | + propTypes: any, |
| 66 | + ... |
| 67 | + }; |
| 68 | + |
| 69 | + declare type $HoistedStatics<S, C> = $Call< |
| 70 | + & (empty => $Diff<S, REACT_STATICS>) |
| 71 | + & (any => $Diff<S, $ObjMap<C, any> & REACT_STATICS>), |
| 72 | + C |
| 73 | + >; |
| 74 | + |
| 75 | + /* |
| 76 | + TP - target component props |
| 77 | + T - target component statics |
| 78 | + S - source component statics |
| 79 | + */ |
| 80 | + declare function hoistNonReactStatics<TP, T, S, C: { [key: string]: true, ... }>( |
| 81 | + TargetComponent: React$ComponentType<TP> & T, |
| 82 | + SourceComponent: React$ComponentType<any> & S, |
| 83 | + customStatics?: C |
| 84 | + ): React$ComponentType<TP> & $HoistedStatics<S, C> & T; |
| 85 | + |
| 86 | + declare export default typeof hoistNonReactStatics; |
| 87 | +} |
0 commit comments