index.d.ts 1.9 KB

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