Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

HOC – Type '{…}' is not assignable to type 'IntrinsicAttributes & PropType'

Hi I’m getting this error :

Type '{ children: Element; onClickOutside: () => void; }' is not assignable to type 'IntrinsicAttributes & PopUpWrapperProps'.
Property 'children' does not exist on type 'IntrinsicAttributes & PopUpWrapperProps'.ts(2322)

when trying to use <PopUpWrapper> in InfoIcon.tsx, I’m guessing it comes from a bad typing in withPortal.tsx but I tried many things and didn’t get the error to disappear…
Do you have any idea on how to solve this ?


Files :

withPortal.tsx

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const withPortal = <P extends object>(Component : React.ComponentType<P>, querySelector = "#portal") => (props : P)  => {
    const isMounted = useMounted(null)
    return isMounted && ReactDOM.createPortal(
        <Component {...props}/>, 
        document.querySelector(querySelector)
    )
}

export default withPortal

PopUpWrapper.tsx

interface PopUpWrapperProps {
    onClickOutside: () => void
}

const PopUpWrapper : React.FC<PopUpWrapperProps> = ({children, onClickOutside}) => {

    ...

    return <div className={styles.popup_wrapper} ref={ref} onClick={handleClick}>
        {children}
    </div>
}

export default withPortal(PopUpWrapper)

InfoIcon.tsx

interface InfoIconProps {
    src: string,
    alt: string
    className?: string,
    isProtected?: boolean
}

const InfoIcon : React.FC<InfoIconProps> = ({
    src, alt, children, className = "", isProtected = true
}) => {

    ...

    return <div className={styles.info_icon}>
    
        ...
        
        {
            identity === Identity.Testing && 
            <PopUpWrapper onClickOutside={cancelIdendityTest}> //error here
                <IdentityPopup />
            </PopUpWrapper>
        }
    </div>
}

export default InfoIcon;

>Solution :

Just add children to your props type:

interface PopUpWrapperProps {
    onClickOutside: () => void,
    children: any
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading