Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 为什么我会收到关于过载呼叫的错误?_Reactjs_Typescript_Redux - Fatal编程技术网

Reactjs 为什么我会收到关于过载呼叫的错误?

Reactjs 为什么我会收到关于过载呼叫的错误?,reactjs,typescript,redux,Reactjs,Typescript,Redux,下午好,我在使用createStore时收到这个错误,有人能解释一下我做错了什么吗 TypeScript error in /workspace/weatherAppTypescript/App/appfrontend/src/redux/store/index.ts(7,31): No overload matches this call. Overload 1 of 2, '(reducer: Reducer<CityProps, any>, enhancer?: Store

下午好,我在使用createStore时收到这个错误,有人能解释一下我做错了什么吗

TypeScript error in /workspace/weatherAppTypescript/App/appfrontend/src/redux/store/index.ts(7,31):
No overload matches this call.
  Overload 1 of 2, '(reducer: Reducer<CityProps, any>, enhancer?: StoreEnhancer<unknown, unknown> | undefined): Store<CityProps, any>', gave the following error.
    Argument of type '(state: CityProps | undefined, action: any) => { temp: any; feelslike: any; cityname: any; weatherdesc: any; } | { cityname: any; temp?: undefined; feelslike?: undefined; weatherdesc?: undefined; }' is not assignable to parameter of type 'Reducer<CityProps, any>'.
      Type '{ temp: any; feelslike: any; cityname: any; weatherdesc: any; } | { cityname: any; temp?: undefined; feelslike?: undefined; weatherdesc?: undefined; }' is not assignable to type 'CityProps'.
        Type '{ cityname: any; temp?: undefined; feelslike?: undefined; weatherdesc?: undefined; }' is not assignable to type 'CityProps'.
          Types of property 'temp' are incompatible.
            Type 'undefined' is not assignable to type 'number'.
  Overload 2 of 2, '(reducer: Reducer<CityProps, any>, preloadedState?: { temp: number; feelslike: number; cityname: string; weatherdesc: string; } | undefined, enhancer?: StoreEnhancer<unknown, {}> | undefined): Store<...>', gave the following error.
    Argument of type '(state: CityProps | undefined, action: any) => { temp: any; feelslike: any; cityname: any; weatherdesc: any; } | { cityname: any; temp?: undefined; feelslike?: undefined; weatherdesc?: undefined; }' is not assignable to parameter of type 'Reducer<CityProps, any>'.  TS2769

    5 | 
    6 | export default function configureStore() {
  > 7 |     const store = createStore(weatherApp);
      |                               ^
    8 |     return store
    9 | }
这是我的减速机:

    temp: 0,
    feelslike: 0,
    cityname: "London",
    weatherdesc: ""
}

export function weatherApp(state = initialState, action: any) {
    switch (action.type) {
        case 'changeCity': {
        return {
            temp: action.temp,
            feelslike: action.feelslike,
            cityname: action.cityname,
            weatherdesc: action.weatherdesc
        }
        }
        case 'changeAPI': {
        return {
            cityname: action.cityname
        }
    }
        default:
        return state;
    }
这是CityProps界面:

export interface CityProps {
    temp: number;
    feelslike: number;
    cityname: string;
    weatherdesc: string;
}

非常感谢你!我真的不知道如何解决这个问题,我已经试了好几个小时了。。。。非常感谢所有帮助我的人^ ^

,因为
weatherApp
是函数,
createStore
希望第一个参数是object

无论您如何使用
rootReducer
,都要将rootReducer作为第一个参数传递。但首先,做出改变
const rootReducer=combinereducer({weatherApp:weatherApp})

非常感谢您,但现在fnction changeCity返回未定义-
export interface CityProps {
    temp: number;
    feelslike: number;
    cityname: string;
    weatherdesc: string;
}