UNPKG

1.69 kBTypeScriptView Raw
1import * as React from "react";
2
3interface REACT_STATICS {
4 childContextTypes: true;
5 contextType: true;
6 contextTypes: true;
7 defaultProps: true;
8 displayName: true;
9 getDefaultProps: true;
10 getDerivedStateFromError: true;
11 getDerivedStateFromProps: true;
12 mixins: true;
13 propTypes: true;
14 type: true;
15}
16
17interface KNOWN_STATICS {
18 name: true;
19 length: true;
20 prototype: true;
21 caller: true;
22 callee: true;
23 arguments: true;
24 arity: true;
25}
26
27interface MEMO_STATICS {
28 "$$typeof": true;
29 compare: true;
30 defaultProps: true;
31 displayName: true;
32 propTypes: true;
33 type: true;
34}
35
36interface FORWARD_REF_STATICS {
37 "$$typeof": true;
38 render: true;
39 defaultProps: true;
40 displayName: true;
41 propTypes: true;
42}
43
44declare namespace hoistNonReactStatics {
45 type NonReactStatics<
46 S extends React.ComponentType<any>,
47 C extends {
48 [key: string]: true;
49 } = {},
50 > = {
51 [
52 key in Exclude<
53 keyof S,
54 S extends React.MemoExoticComponent<any> ? keyof MEMO_STATICS | keyof C
55 : S extends React.ForwardRefExoticComponent<any> ? keyof FORWARD_REF_STATICS | keyof C
56 : keyof REACT_STATICS | keyof KNOWN_STATICS | keyof C
57 >
58 ]: S[key];
59 };
60}
61
62declare function hoistNonReactStatics<
63 T extends React.ComponentType<any>,
64 S extends React.ComponentType<any>,
65 C extends {
66 [key: string]: true;
67 } = {},
68>(
69 TargetComponent: T,
70 SourceComponent: S,
71 customStatic?: C,
72): T & hoistNonReactStatics.NonReactStatics<S, C>;
73
74export = hoistNonReactStatics;