1
1
// Copied directly from:
2
2
// https://github.com/mridgway/hoist-non-react-statics/blob/main/src/index.js
3
- // https://unpkg.com/browse/@types /[email protected] .1 /index.d.ts
3
+ // https://unpkg.com/browse/@types /[email protected] .6 /index.d.ts
4
4
5
5
/**
6
6
* Copyright 2015, Yahoo! Inc.
7
7
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
8
8
*/
9
- import type {
10
- ComponentType ,
11
- ForwardRefExoticComponent ,
12
- MemoExoticComponent ,
13
- } from 'react'
9
+ import type { ForwardRefExoticComponent , MemoExoticComponent } from 'react'
14
10
import { ForwardRef , Memo , isMemo } from '../utils/react-is'
15
11
16
12
const REACT_STATICS = {
@@ -70,19 +66,19 @@ function getStatics(component: any) {
70
66
}
71
67
72
68
export type NonReactStatics <
73
- S extends ComponentType < any > ,
69
+ Source ,
74
70
C extends {
75
71
[ key : string ] : true
76
72
} = { } ,
77
73
> = {
78
74
[ key in Exclude <
79
- keyof S ,
80
- S extends MemoExoticComponent < any >
75
+ keyof Source ,
76
+ Source extends MemoExoticComponent < any >
81
77
? keyof typeof MEMO_STATICS | keyof C
82
- : S extends ForwardRefExoticComponent < any >
78
+ : Source extends ForwardRefExoticComponent < any >
83
79
? keyof typeof FORWARD_REF_STATICS | keyof C
84
80
: keyof typeof REACT_STATICS | keyof typeof KNOWN_STATICS | keyof C
85
- > ] : S [ key ]
81
+ > ] : Source [ key ]
86
82
}
87
83
88
84
const defineProperty = Object . defineProperty
@@ -93,12 +89,15 @@ const getPrototypeOf = Object.getPrototypeOf
93
89
const objectPrototype = Object . prototype
94
90
95
91
export default function hoistNonReactStatics <
96
- T extends ComponentType < any > ,
97
- S extends ComponentType < any > ,
98
- C extends {
92
+ Target ,
93
+ Source ,
94
+ CustomStatic extends {
99
95
[ key : string ] : true
100
96
} = { } ,
101
- > ( targetComponent : T , sourceComponent : S ) : T & NonReactStatics < S , C > {
97
+ > (
98
+ targetComponent : Target ,
99
+ sourceComponent : Source ,
100
+ ) : Target & NonReactStatics < Source , CustomStatic > {
102
101
if ( typeof sourceComponent !== 'string' ) {
103
102
// don't hoist over string (html) components
104
103
0 commit comments