1

I am debugging a code I have not written, and I am new to typescript. I am getting a TS2339 error

Property 'InputFiles' does not exist on type '{}'.
I understand that this means that I am missing to hand-over the property, but what should I modify?

Within UI\src\containers\FileUploaderContainer.tsx, I have something like

export class FileUploader extends React.Component<any, any> {
    render() {
        return ( <div><UploadFileFormContainer /></div> );
    }
}

const FileUploaderContainer: { any } = connect(
    state => ({ InputFiles: state.InputFiles }),  // error occurs here
    dispatch => ({})
)(FileUploader);

export default FileUploaderContainer;

Background

If I hover in Visual Studio above connect, I see

(alias) connect<{InputFiles: any;}, any, {}, {}>(mapStateToProps: MapStateToPropsParam<{
InputFIles: any; }, {}, {}>, mapDispatchToProps: MapDispatchToPropsNonObject<any,{}>):
InterferableComponentEnhancerWithPropos<any,{}> (+ 14 overloads)
import connect

Related questions

The following issues did not help me to resolve my issue

B--rian
  • 5,578
  • 10
  • 38
  • 89
  • Well, your `state` is (somehow) defined as being `{}`, so TS doesn't know of any properties on it. – VLAZ Oct 29 '19 at 08:52
  • @VLAZ May you be so kind and guide me here? I am assuming that I should replace one of the `any`? I still not too comfortable with the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)... – B--rian Oct 29 '19 at 09:00
  • @Pac0 May you elaborate a bit, please? Do you mean I should add an `as any` at the very end? – B--rian Oct 29 '19 at 09:14
  • what is the type definition for first argument of your connect function? – MarcinL Oct 29 '19 at 09:15

1 Answers1

3

You may just add any type for the state like this:

const FileUploaderContainer : any = connect(
  (state : any ) => ({ InputFiles: state.InputFiles }),  // just add any type on state
  dispatch => ({})
)(FileUploader);
B--rian
  • 5,578
  • 10
  • 38
  • 89
vothanhdat
  • 89
  • 1
  • 7