hoist.d.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import { AnyComponent } from '../types';
  3. /**
  4. * Adapted from hoist-non-react-statics to avoid the react-is dependency.
  5. */
  6. declare const REACT_STATICS: {
  7. childContextTypes: boolean;
  8. contextType: boolean;
  9. contextTypes: boolean;
  10. defaultProps: boolean;
  11. displayName: boolean;
  12. getDefaultProps: boolean;
  13. getDerivedStateFromError: boolean;
  14. getDerivedStateFromProps: boolean;
  15. mixins: boolean;
  16. propTypes: boolean;
  17. type: boolean;
  18. };
  19. declare const KNOWN_STATICS: {
  20. name: boolean;
  21. length: boolean;
  22. prototype: boolean;
  23. caller: boolean;
  24. callee: boolean;
  25. arguments: boolean;
  26. arity: boolean;
  27. };
  28. declare const FORWARD_REF_STATICS: {
  29. $$typeof: boolean;
  30. render: boolean;
  31. defaultProps: boolean;
  32. displayName: boolean;
  33. propTypes: boolean;
  34. };
  35. declare const MEMO_STATICS: {
  36. $$typeof: boolean;
  37. compare: boolean;
  38. defaultProps: boolean;
  39. displayName: boolean;
  40. propTypes: boolean;
  41. type: boolean;
  42. };
  43. type OmniComponent = AnyComponent;
  44. type ExcludeList = {
  45. [key: string]: true;
  46. };
  47. export type NonReactStatics<S extends OmniComponent, C extends ExcludeList = {}> = {
  48. [key in Exclude<keyof S, S extends React.MemoExoticComponent<any> ? keyof typeof MEMO_STATICS | keyof C : S extends React.ForwardRefExoticComponent<any> ? keyof typeof FORWARD_REF_STATICS | keyof C : keyof typeof REACT_STATICS | keyof typeof KNOWN_STATICS | keyof C>]: S[key];
  49. };
  50. export default function hoistNonReactStatics<T extends OmniComponent, S extends OmniComponent, C extends ExcludeList = {}>(targetComponent: T, sourceComponent: S, excludelist?: C | undefined): T & NonReactStatics<S, C>;
  51. export {};