// I have no idea how any of this works. But it works. Thanks Jared. https://gist.github.com/jaredpalmer/80982b3d787359762506fce578108358 import * as React from 'react'; export type AssignableRef = | { bivarianceHack(instance: ValueType | null): void; }['bivarianceHack'] | React.MutableRefObject | null; export type Use = React.ElementType; export type PropsWithUse = ComponentProps & Omit, 'use' | keyof ComponentProps> & { use?: string | ComponentType; }; export type PropsFromUse = (PropsWithUse & { use: string | ComponentType; }) & PropsWithUse; export type ComponentWithForwardedRef< ElementType extends React.ElementType, ComponentProps > = React.ForwardRefExoticComponent< ComponentProps & React.HTMLProps> & React.ComponentPropsWithRef >; export interface ComponentWithUse { (props: PropsWithUse): React.ReactElement | null; (props: PropsWithUse): React.ReactElement | null; displayName?: string; propTypes?: React.WeakValidationMap>; contextTypes?: React.ValidationMap; defaultProps?: Partial>; useProps?: (props?: Partial, config?: { themeKey?: string }) => any; } export function forwardRefWithUse( comp: (props: PropsFromUse, ref: React.RefObject) => React.ReactElement | null ) { return (React.forwardRef(comp as any) as unknown) as ComponentWithUse; }