@primer/react
Version:
An implementation of GitHub's Primer Design System using React
31 lines (30 loc) • 1.36 kB
TypeScript
import { SlotMarker } from "./types/Slots.js";
import * as React$1 from "react";
import { JSX } from "react";
//#region src/utils/polymorphic.d.ts
type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
/**
* Infers the OwnProps if E is a ForwardRefExoticComponentWithAs
*/
type ForwardRefExoticComponent$1<E, OwnProps> = React$1.ForwardRefExoticComponent<Merge<E extends React$1.ElementType ? React$1.ComponentPropsWithRef<E> : never, OwnProps & {
as?: E;
}>>;
interface ForwardRefComponent<IntrinsicElementString, OwnProps = {}> extends ForwardRefExoticComponent$1<IntrinsicElementString, OwnProps>, SlotMarker {
/**
* When `as` prop is passed, use this overload.
* Merges original own props (without DOM props) and the inferred props
* from `as` element with the own props taking precedence.
*
* We explicitly avoid `React.ElementType` and manually narrow the prop types
* so that events are typed when using JSX.IntrinsicElements.
*/
<As = IntrinsicElementString>(props: As extends '' ? {
as: keyof JSX.IntrinsicElements;
} : As extends React$1.ComponentType<infer P> ? Merge<P, OwnProps & {
as: As;
}> : As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & {
as: As;
}> : never): React$1.ReactElement<any> | null;
}
//#endregion
export type { ForwardRefComponent, Merge };