Argument of type 'xxxx' is not assignable to parameter of type 'JSXElementConstructor<never>'

Viewed 628

I am taking a typescript course in udemy. link

import { connect } from 'react-redux';
import { Todo, fetchTodos } from '../actions';
import { StoreState } from '../reducers';

interface AppProps {
  todos: Todo[];
  fetchTodos(): any;
}

class _App extends React.Component<AppProps> {
  render() {
    return <div>Hi there!</div>;
  }
}

const mapStateToProps = ({ todos }: StoreState): { todos: Todo[] } => {
  return { todos };
};

export const App = connect(
  mapStateToProps,
  { fetchTodos }
)(_App);

however this error appears:

Argument of type 'typeof _App' is not assignable to parameter of type 'JSXElementConstructor<never>'.
  Type 'typeof _App' is not assignable to type 'new (props: never) => Component<any, any, any>'.
    Construct signature return types '_App' and 'Component<any, any, any>' are incompatible.
      The types of 'refs' are incompatible between these types.
        Type '{ [key: string]: React.ReactInstance; }' is not assignable to type '{ [key: string]: import("C:/Users/xxxxxxxxxxxxx/271-connecting/rrts/node_modules/@types/react-redux/node_modul
es/@types/react/index").ReactInstance; }'.
          'string' index signatures are incompatible.
Node'.
                      Type '{}' is not assignable to type 'ReactNode'.  TS2345

May I know how to solve this?.....................................

I guess the function return by connect( mapStateToProps, { fetchTodos } ) assume the argument is a react component that take no props?

0 Answers
Related