javascript 无法将类型指派给类型“IntrinsicAttributes & { children?”:ReactNode;}',属性

sqougxex  于 2022-12-10  发布在  Java
关注(0)|答案(1)|浏览(254)

我曾试图找出这个错误的解决办法,但没有成功。
我收到这种类型的错误:
键入“{ mailData:邮件发送属性;}"不能赋值给类型“IntrinsicAttributes & { children?:类型“IntrinsicAttributes & { children?”上不存在属性“mailData”:ReactNode;}“中定义。
我的代码是这样的:

<SocialShare mailData={_mailData} />

const _mailData:mailSendProps = {
    url:_seoData.actualURL ?  _seoData.actualURL : '',
    msid:_seoData.msid ?  _seoData.msid : '',
    articlelink:`${_seoData.actualURL}?frm=mailtofriend&intenttarget=no`,
    syn:_seoData.description ?  _seoData.description : 'Page description',
    pageTitle:_seoData.title ? _seoData.title : 'Title VideoShow ',
    subject:`Economictimes.com: ${_seoData.title}` || ''
  }

export interface mailSendProps {
    url?: string,
    msid?:string,
    articlelink?:string,
    syn?:string,
    pageTitle?:string,
    subject?:string
  }


const SocialShare: NextPage = (props?:any) => {
  const url = props.mailData.url && props.mailData.url != '' ? props.mailData.url : ''
  const [showUrl, setShowUrl] = useState('no');
  const [showEmbed, setShowEmbed] = useState('no');
  const [showMail, setShowMail] = useState('no');

  const showHandlerModule = (val:string)=>{
    let _url = '';
    let _embed = '';
    if(val === 'url'){
      _url = 'yes';
      _embed = 'no'
    }else if(val === 'embed'){
      _url = 'no';
      _embed = 'yes'
    }
    setShowUrl(_url);
    setShowEmbed(_embed)
  }
  const closeHandler = ()=>{
    setShowUrl('no');
    setShowEmbed('no')
  }
  const closeMailHandler = ()=>{
    setShowMail('no')
  }
  return (
    <>
        <Share />
        <div className={styles.codeMailVideo}>
          <span onClick={()=>{setShowMail('yes')}} className={styles.email} title="Email this video"></span>
          {
            showMail === 'yes' ? <MailSendTemplate mailData={props.mailData} onclickhandler={closeMailHandler} /> : ''
          }
        </div>
        <div className={styles.codeVideo}>
          <span onClick={()=>{showHandlerModule('url')}}>Copy URL</span>
          {
            showUrl === 'yes' ?  <span className={styles.copyUrlSec}>
            <input readOnly type="text" value={url} className={styles.readUrl} />
            <i  className={styles.close} onClick={closeHandler}></i>
          </span> : ''
          }
        </div>
        <div className={styles.codeVideo}>
          <span onClick={()=>{showHandlerModule('embed')}}>Embed</span>
          {
            showEmbed === 'yes' ? <span className={styles.copyUrlSec}>
            <textarea readOnly defaultValue={`<iframe mozallowfullscreen="true" webkitallowfullscreen="true" allowfullscreen="true" width="560" height="420" frameborder="0" defaultValue=${url} src=${url}></iframe>`}>{

            }</textarea>
            <i  className={styles.close} onClick={closeHandler}></i>
          </span> : ''
          }

        </div>
    </>
  );
};

解决方案是什么?

ctehm74n

ctehm74n1#

TypeScript对类型检查很严格。你需要定义你的SocialShare属性的形状--也就是说你在这个组件中会收到什么属性,否则TypeScript会标记为“properties do not exist”:
尝试添加另一个SocialShareProps接口,如下所示:

interface SocialShareProps {
  mailData: mailSendProps;
}

const SocialShare: NextPage<SocialShareProps> = (props) => {
...

相关问题