From 1cd1385fc4d6845a209123ce68247ecb881daaf0 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Fri, 6 Dec 2024 02:25:03 -0600 Subject: [PATCH] Update `hoist-non-react-statics` implementation --- src/utils/hoistStatics.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/utils/hoistStatics.ts b/src/utils/hoistStatics.ts index fccbc8cb7..d47668210 100644 --- a/src/utils/hoistStatics.ts +++ b/src/utils/hoistStatics.ts @@ -1,16 +1,12 @@ // Copied directly from: // https://github.com/mridgway/hoist-non-react-statics/blob/main/src/index.js -// https://unpkg.com/browse/@types/hoist-non-react-statics@3.3.1/index.d.ts +// https://unpkg.com/browse/@types/hoist-non-react-statics@3.3.6/index.d.ts /** * Copyright 2015, Yahoo! Inc. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. */ -import type { - ComponentType, - ForwardRefExoticComponent, - MemoExoticComponent, -} from 'react' +import type { ForwardRefExoticComponent, MemoExoticComponent } from 'react' import { ForwardRef, Memo, isMemo } from '../utils/react-is' const REACT_STATICS = { @@ -70,19 +66,19 @@ function getStatics(component: any) { } export type NonReactStatics< - S extends ComponentType, + Source, C extends { [key: string]: true } = {}, > = { [key in Exclude< - keyof S, - S extends MemoExoticComponent + keyof Source, + Source extends MemoExoticComponent ? keyof typeof MEMO_STATICS | keyof C - : S extends ForwardRefExoticComponent + : Source extends ForwardRefExoticComponent ? keyof typeof FORWARD_REF_STATICS | keyof C : keyof typeof REACT_STATICS | keyof typeof KNOWN_STATICS | keyof C - >]: S[key] + >]: Source[key] } const defineProperty = Object.defineProperty @@ -93,12 +89,15 @@ const getPrototypeOf = Object.getPrototypeOf const objectPrototype = Object.prototype export default function hoistNonReactStatics< - T extends ComponentType, - S extends ComponentType, - C extends { + Target, + Source, + CustomStatic extends { [key: string]: true } = {}, ->(targetComponent: T, sourceComponent: S): T & NonReactStatics { +>( + targetComponent: Target, + sourceComponent: Source, +): Target & NonReactStatics { if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components