Home>

This code raises an errorType '{error: string; closeCallback: ()= > void; } 'is not assignable to type' string '...

this.state.errorInfoForShow &
&
   <
StampErrorModal
       error= {this.state.errorInfoForShow}
       closeCallback= {this.closeErrorInfoModal}
   />

Although the types in the function are spelled out correctly

const StampErrorModal= (error: string | null, closeCallback: ()= >
 any)= >
 {
 return (
     stampErrorModalTemplate (error, closeCallback)
 );
}
export default StampErrorModal;

And everything works if you change

<
StampErrorModal
     error= {this.state.errorInfoForShow}
     closeCallback= {this.closeErrorInfoModal}
 />

on

StampErrorModal (this.state.errorInfoForShow, this.closeErrorInfoModal)

But I need not to touch the module in which the code is called, but to change only the StampErrorModal function

one props object should be passed to the component method, and you pass two, when directly called. In the case of attributes, they are collected into one object of the specified type. Therefore, the error

Grundy2021-12-28 04:48:09

Thanks, now everything works

Марина Петрова2021-12-28 04:48:09
  • Answer # 1

    Component props enter a functional react not as a list of arguments, but as fields in an object with props, i.e. when you pass props to a component:

    <
    StampErrorModal
         error= {this.state.errorInfoForShow}
         closeCallback= {this.closeErrorInfoModal}
     />
    

    then in the StampErrorModal function you will receive one argumentprops(object) with fieldserrorandcloseCallback

    try this:

    type Props= {
        error: string | null,
        closeCallback: ()= >
     any
    }
    const StampErrorModal= ({error, closeCallback}: Props)= >
     {