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

Expected 4 type arguments, but got 1. #140

Closed haani104 closed 6 years ago

haani104 commented 6 years ago

I am getting this error can anyone help ?

screen shot 2018-04-27 at 19 29 06

This is the type definition of IStoreState

export interface IStoreState {
    languageName: string;
    enthusiasmLevel: number;
}
etlolap commented 6 years ago

Is it duplicate to https://github.com/Microsoft/TypeScript-React-Starter/issues/136?

haani104 commented 6 years ago

Not sure if this is the solution to it, but this worked for me

I imported EnthusiasmAction

import { EnthusiasmAction } from './actions/index'; and used like below

const store = createStore<IStoreState, EnthusiasmAction, any, any>(enthusiam, { enthusiasmLevel: 1, languageName: 'TypeScript' });

qingnote commented 6 years ago

If don't know what the type is, try to describe it as 'any' const store = createStore<StoreState,any,any,any>(enthusiasm, { enthusiasmLevel: 1, languageName: 'TypeScript', });

Vlad412 commented 5 years ago

Didn't work, why it's closed and readme not updated

zant commented 5 years ago

The solution presented by @haani104 is good, but for me was incomplete, i had to make tihis change in my /reducers/index.tsx:

import { Reducer } from "redux";

export const enthusiasm: Reducer = (
  state: StoreState,
  action: EnthusiasmAction
): StoreState => {
  switch (action.type) {
    case INCREMENT_ENTHUSIASM:
      return { ...state, enthusiasmLevel: state.enthusiasmLevel + 1 };
    case DECREMENT_ENTHUSIASM:
      return { ...state, enthusiasmLevel: state.enthusiasmLevel - 1 };
  }
  return state;
};

Basically, createStore expects a function of type Reducer as one of it arguments, and in the tutorial, we are declaring it as a plain function.