“错误”类型的参数不能分配给“EAlertType”类型的参数

时间:2021-07-20 15:53:25

标签: typescript react-redux redux-toolkit

我正在使用 redux 工具包编写 redux 存储,但遇到了问题,我的代码中有 Enum 类型,当我尝试为它分配一个字符串时,例如“错误”,它给了我这个错误.

    self.editors[index.row()] = editor
    QtCore.QTimer.singleShot(0, lambda: self.sizeHintChanged.emit(index))

    return editor

枚举

Argument of type '"error"' is not assignable to parameter of type 'EAlertType'.ts(2345)

我的代码

export enum EAlertType {
  info = 'info',
  success = 'success',
  warning = 'warning',
  error = 'error',
  default = 'default',
}
export interface IAlert {
  msg: string,
  alertType: EAlertType,
  timeout: number,
  id: string,
}

我正在使用 react-toastify lib 来做吐司

1 个答案:

答案 0 :(得分:0)

我用这个解决了

TEST_NOTSELECTED_C_1