1

嗨,我收到此错误:

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

尝试使用<PopUpWrapper>in时InfoIcon.tsx,我猜它来自输入错误,withPortal.tsx但我尝试了很多东西并没有让错误消失......你知道如何解决这个问题吗?


文件:

withPortal.tsx

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)

信息图标.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;
4

1 回答 1

2

只需将孩子添加到您的道具类型中:

interface PopUpWrapperProps {
    onClickOutside: () => void,
    children: any
}
于 2021-12-15T11:21:14.617 回答