UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

27 lines (19 loc) 856 B
import { forwardRef } from 'react'; // Mostly taken from https://github.com/total-typescript/react-typescript-tutorial/blob/main/src/08-advanced-patterns/72-as-prop-with-forward-ref.solution.tsx /** * Distributive Omit utility type that works correctly with union types */ /** * Fixed version of forwardRef that provides better type inference for polymorphic components */ // TODO: figure out how to change this type so we can set displayName // like this: `ComponentName.displayName = 'DisplayName' instead of using workarounds /** * Cast forwardRef to the fixed version with better type inference */ const fixedForwardRef = forwardRef; /** * Simplified polymorphic props type that handles the common pattern of * `DistributiveOmit<ComponentPropsWithRef<ElementType extends As ? DefaultElement : As>, 'as'>` */ export { fixedForwardRef };