Skip to content

Commit 430243e

Browse files
committed
Update hoist-non-react-statics implementation
1 parent 5b40546 commit 430243e

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/utils/hoistStatics.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
// Copied directly from:
22
// 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
44

55
/**
66
* Copyright 2015, Yahoo! Inc.
77
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
88
*/
9-
import type {
10-
ComponentType,
11-
ForwardRefExoticComponent,
12-
MemoExoticComponent,
13-
} from 'react'
9+
import type { ForwardRefExoticComponent, MemoExoticComponent } from 'react'
1410
import { ForwardRef, Memo, isMemo } from '../utils/react-is'
1511

1612
const REACT_STATICS = {
@@ -70,19 +66,19 @@ function getStatics(component: any) {
7066
}
7167

7268
export type NonReactStatics<
73-
S extends ComponentType<any>,
69+
Source,
7470
C extends {
7571
[key: string]: true
7672
} = {},
7773
> = {
7874
[key in Exclude<
79-
keyof S,
80-
S extends MemoExoticComponent<any>
75+
keyof Source,
76+
Source extends MemoExoticComponent<any>
8177
? keyof typeof MEMO_STATICS | keyof C
82-
: S extends ForwardRefExoticComponent<any>
78+
: Source extends ForwardRefExoticComponent<any>
8379
? keyof typeof FORWARD_REF_STATICS | keyof C
8480
: keyof typeof REACT_STATICS | keyof typeof KNOWN_STATICS | keyof C
85-
>]: S[key]
81+
>]: Source[key]
8682
}
8783

8884
const defineProperty = Object.defineProperty
@@ -93,12 +89,15 @@ const getPrototypeOf = Object.getPrototypeOf
9389
const objectPrototype = Object.prototype
9490

9591
export default function hoistNonReactStatics<
96-
T extends ComponentType<any>,
97-
S extends ComponentType<any>,
98-
C extends {
92+
Target,
93+
Source,
94+
CustomStatic extends {
9995
[key: string]: true
10096
} = {},
101-
>(targetComponent: T, sourceComponent: S): T & NonReactStatics<S, C> {
97+
>(
98+
targetComponent: Target,
99+
sourceComponent: Source,
100+
): Target & NonReactStatics<Source, CustomStatic> {
102101
if (typeof sourceComponent !== 'string') {
103102
// don't hoist over string (html) components
104103

0 commit comments

Comments
 (0)