UNPKG

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