【问题标题】:Typescript: How do you add a type declaration to the severity property in React Alert?Typescript:如何向 React Alert 中的严重性属性添加类型声明?
【发布时间】:2021-11-01 21:27:49
【问题描述】:

我已经为传入的数据创建了一个类型声明对象,但无论我似乎尝试将其定义为属性“严重性”的类型,它都令人不安。它想要的(如下所示)似乎不是一个选项。我只是想知道除了“任何”之外是否还有一种我可以使用的类型可以为此工作?或者,因为它是定制的,所以我唯一的选择是什么?

这就是我抛出以下错误的原因:

type ticketData = {
  name: string;
  title: string;
  onClose: () => void;
  message: string[];
}

https://mui.com/components/snackbars/

【问题讨论】:

    标签: javascript typescript material-ui


    【解决方案1】:

    对于 muiAlert 提供的颜色,您必须提及以下任何选项:

    name: 'success' | 'info' | 'warning' | 'error' | undefined
    

    检查 api 链接 - https://mui.com/api/alert/

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2019-08-09
      • 2017-09-10
      • 2018-12-05
      • 2021-05-10
      • 1970-01-01
      • 2019-06-06
      • 2020-09-17
      • 2017-12-31
      相关资源
      最近更新 更多