/** * Based on https://github.com/react-bootstrap/react-bootstrap/blob/9380dfb9ac8ecf3f49f2f83f35cc22025aa6d7a8/src/helpers.ts */ import React from "react"; /** * Constructs a type by picking all properties from Type and then removing the props in common with Keys. * * eg: Omit<{a: any, b: any}, {b: any, c: any}> = {a: any} */ export type Omit = Pick>; /** * Constructs the type of the props of a Component 'Inner', adding also the props in P * * eg: ReplaceProps<'a', {href: string | number }> would be creating a type of the props of 'a', replacing the type of the prop 'href' with a new type 'string | number' * eg: ReplaceProps<'a', { anotherProp: string }> would be creating a type of the props of 'a' + 'anotherProp: string' */ export type ReplaceProps = Omit< React.ComponentPropsWithRef, P > & P; export interface TestId { "data-testid"?: string; } /** * Type of the props of a component that has an "as: React.ElementType" property. * **To have a proper type checking, the component type must be 'AsComponent'** * * eg: interface MyButtonProps extends AsPropsWthoutChildren { oneProp: any } */ export interface AsPropsWithoutChildren extends TestId { className?: string; as?: As; } /** * Type of the props of a component with children, that support changing the ElementType with a property "as: React.ElementType". * **To have a proper type checking, the component type must be 'AsComponent'** * * eg: interface MyButtonProps extends AsPropsWithChildren { oneProp: any } */ export type AsPropsWithChildren< As extends React.ElementType = React.ElementType > = React.PropsWithChildren>; /** * Type of a component with forwardRef, that support changing the ElementType with a property "as: React.ElementType". * * By using this type, the component will have a good type checking, by supporting as well the properties of the "as" element type. * **To have a proper type checking, the component props must extend 'AsPropsWthoutChildren' or 'AsPropsWithChildren'** * * eg: * type Button = AsComponent<'button', MyButtonProps>; * conts Button: Button = forwardRef({as: Component = 'button', ...rest }, ref) => { * return * } * ``` */ export interface AsComponent { ( props: React.PropsWithChildren & P>>, context?: any ): React.ReactElement | null; propTypes?: any; contextTypes?: any; defaultProps?: Partial

; displayName?: string; }