Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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
Javascript React/Redux reducer类型脚本错误(类型';未定义';不可分配给类型ISupplierState)_Javascript_Reactjs_Typescript_Redux_Types - Fatal编程技术网

Javascript React/Redux reducer类型脚本错误(类型';未定义';不可分配给类型ISupplierState)

Javascript React/Redux reducer类型脚本错误(类型';未定义';不可分配给类型ISupplierState),javascript,reactjs,typescript,redux,types,Javascript,Reactjs,Typescript,Redux,Types,我已经很长一段时间没能解决这个问题了,尽管我已经搜索了很多有类似问题的页面 我收到以下错误: src/app/store/instructor/supplier/reducer.tsx TypeScript error in src/app/store/instructor/supplier/reducer.tsx(11,7): Type '(state: ISupplierState | undefined, action: AnyAction) => { loading: true;

我已经很长一段时间没能解决这个问题了,尽管我已经搜索了很多有类似问题的页面

我收到以下错误:

src/app/store/instructor/supplier/reducer.tsx
TypeScript error in src/app/store/instructor/supplier/reducer.tsx(11,7):
Type '(state: ISupplierState | undefined, action: AnyAction) => { loading: true; suppliers: Supplier[]; errors?: string | undefined; } | { suppliers: any; loading: false; errors?: string | undefined; } | { ...; } | undefined' is not assignable to type 'Reducer<ISupplierState, AnyAction>'.
  Type '{ loading: true; suppliers: Supplier[]; errors?: string | undefined; } | { suppliers: any; loading: false; errors?: string | undefined; } | { loading: false; errors: any; suppliers: Supplier[]; } | undefined' is not assignable to type 'ISupplierState'.
    Type 'undefined' is not assignable to type 'ISupplierState'.  TS2322

     9 | };
    10 | 
  > 11 | const reducer: Reducer<ISupplierState> = (state = initialState, action) => {
       |       ^
    12 |   switch (action.type) {
    13 |     case ISupplierActionTypes.ISUPPLIER_FETCH: {
    14 |       return {
我理解错误代码,但我能够在另一个reducer上执行非常类似的方法,而不会出现任何问题。所以我不明白为什么这会引起这么多问题

我使用的是
Redux 7.2.0
任何帮助都将不胜感激:)
提前谢谢你。

我道歉。我忘了在我的交换机上添加一个默认返回。。 所以如果你遇到类似的问题,记得检查你的开关

添加以下行解决了这个问题

default: {
    return state;
}
export interface Supplier {
  name: string;
  id: number;
  payment_terms: number;
  address_id: number;
  delivery_time: number;
  bank_id: number;
  company_Type_id: number;
}

export interface ISupplier {
  suppliers: Supplier[];
}

export enum ISupplierActionTypes {
  ISUPPLIER_FETCH = '@@instructor/supplier/REQUEST',
  ISUPPLIER_SUCCESS = '@@instructor/supplier/SUCCESS',
  ISUPPLIER_ERROR = '@@instructor/supplier/ERROR',
}

export interface ISupplierState {
  readonly loading: boolean;
  readonly suppliers: Supplier[];
  readonly errors?: string;
}
default: {
    return state;
}