microsoft / TypeScript-React-Starter

A starter template for TypeScript and React with a detailed README describing how to use the two together.
MIT License
11.09k stars 1.21k forks source link

mapDispatchToProps, Expected 1 arguments, but got 0 #155

Open mjaracz opened 6 years ago

mjaracz commented 6 years ago

I have a problem with connecting a container with Redux, I don't know why my tslint returns this type of error

[ts] Expected 1 arguments, but got 0.

my code looks like belowe

import * as React from 'react';
import { connect, Dispatch } from 'react-redux';
import { StoreState } from '../../duck/types';
import * as actions from "../duck/actions";

class HomeContainer extends React.Component {
  public render() {
    return (
      <img/>
    )
  }
}

const mapStateToProps = (state: StoreState) => {
  users: state.users
}

const mapDispatchToProps = (dispatch: Dispatch<actions.TuserAction>) => {
  return {
    fetchUser: () => dispatch(actions.fetchUser()),
    fetchUserFull: () => dispatch(actions.fetchUserFullfilled()), 
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(HomeContainer);

and this is my action file

import * as constants from '../constants';

export interface IfetchUser {
  type: constants.FETCH_USER
};
export interface IfetchUserFull {
  type: constants.FETCH_USER_FULL,
  payload: object[]
};

export type TuserAction = IfetchUserFull | IfetchUser;

export function fetchUser(): IfetchUser {
  return {
    type: constants.FETCH_USER
  }
};

export function fetchUserFullfilled(payload: object[]): IfetchUserFull {
  return {
    type: constants.FETCH_USER_FULL,
    payload
  }
};
mjaracz commented 6 years ago

from what I checked on the internet it is not a problem with the TSLINT configuration, because adding rules did not help either.

But if there is any rule for tslint, which I did not know, then please let me know ?

lc3t35 commented 6 years ago

Just change

const mapStateToProps = (state: StoreState) => {
  users: state.users
}

by

const mapStateToProps = (state: StoreState, ownProps: any) => {
  ...ownProps,
  users: state.users
}