import { Children, ComponentType, isValidElement, ReactElement, ReactNode, } from 'react'; export function createChildSlot
(name?: string) { const Slot: ComponentType
& { isElementOf: (el: ReactElement) => el is ReactElement
; findElement: ( children?: ReactNode | ReactNode[], ) => ReactElement
| undefined; } = () => null; Slot.displayName = name; Slot.isElementOf = (el): el is ReactElement
=> el.type === Slot; Slot.findElement = (children) => children != null ? Children.toArray(children).find( (child): child is ReactElement
=> isValidElement(child) && Slot.isElementOf(child), ) : undefined; return Slot; }