From 33ca349bcd870f6f70e1115e6d2af56270965846 Mon Sep 17 00:00:00 2001 From: Caleb Pollman Date: Wed, 8 Jan 2025 09:40:00 -0800 Subject: [PATCH] Remove extended and overridden react types --- packages/react/src/primitives/types/view.ts | 60 ++++++++------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/packages/react/src/primitives/types/view.ts b/packages/react/src/primitives/types/view.ts index 6bf95f001b..9aa2cb25dd 100644 --- a/packages/react/src/primitives/types/view.ts +++ b/packages/react/src/primitives/types/view.ts @@ -4,11 +4,17 @@ import { MergeProps } from '@aws-amplify/ui-react-core'; import { AriaProps, BaseComponentProps } from './base'; import { BaseStyleProps } from './style'; +/** + * @deprecated will be removed in a future major version + */ // A utility type to check if a type is any export type IsAny = (Type extends never ? true : false) extends false ? false : true; +/** + * @deprecated will be removed in a future major version + */ export type ElementType = React.ElementType; type AsProp = { @@ -19,6 +25,9 @@ type AsProp = { as?: Element; }; +/** + * @deprecated will be removed in a future major version + */ export type PrimitivePropsWithAs< Props extends BaseViewProps, Element extends ElementType, @@ -29,6 +38,9 @@ type PrimitivePropsWithRef< Element extends ElementType, > = Omit & React.RefAttributes>; +/** + * @deprecated will be removed in a future major version + */ export type PrimitivePropsWithHTMLAttributes< Props extends BaseViewProps, Element extends ElementType, @@ -47,6 +59,9 @@ export type PrimitivePropsWithHTMLAttributes< > : any; +/** + * @deprecated will be removed in a future major version + */ export type PrimitiveProps< Props extends BaseViewProps, Element extends ElementType, @@ -56,59 +71,28 @@ export type PrimitiveProps< >; /** - * @see {React.ForwardRefRenderFunction} - * Modifies return type of `React.ForwardRefRenderFunction` - * to allow usage in React 16 + * @deprecated will be removed in a future major version */ -interface JSElementForwardRefRenderFunction { - // return `JSX.Element` or `null` in place of `React.ReactNode` - (props: P, ref: React.ForwardedRef): React.JSX.Element | null; - displayName?: string | undefined; - // explicit rejected with `never` required due to - // https://github.com/microsoft/TypeScript/issues/36826 - /** - * defaultProps are not supported on render functions - */ - defaultProps?: never | undefined; - /** - * propTypes are not supported on render functions - */ - propTypes?: never | undefined; -} - export interface Primitive< Props extends BaseViewProps, Element extends ElementType, -> extends JSElementForwardRefRenderFunction< - React.ComponentRef, - Props - > {} +> extends React.ForwardRefRenderFunction, Props> {} /** - * @see {React.ForwardRefExoticComponent} - * Modifies return type of `React.ForwardRefExoticComponent` - * to allow usage in React 16 + * @deprecated will be removed in a future major version */ -interface JSXElementForwardRefExoticComponent

{ - // return `React.ReactElement` or `null` in place of `React.ReactNode` - (props: P): React.ReactElement | null; - defaultProps?: Partial

| undefined; - displayName?: string | undefined; - // deprecated in React@19 but needed for backwards compatibility in previous versions - propTypes?: any; - readonly $$typeof: symbol; -} - export interface ForwardRefPrimitive< Props extends BaseViewProps, DefaultElement extends ElementType, -> extends JSXElementForwardRefExoticComponent< +> extends React.ForwardRefExoticComponent< PrimitiveProps > { // overload the JSX constructor to make it accept generics ( props: PrimitiveProps - ): React.ReactElement | null; + ): ReturnType< + React.ForwardRefExoticComponent> + >; } /** @deprecated For internal use only */