【问题标题】:TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'TS2345:“字符串”类型的参数 | undefined' 不能分配给'string' 类型的参数。类型“未定义”不可分配给类型“字符串”
【发布时间】:2019-12-11 02:21:52
【问题描述】:

我已经定义了如下类型

interface LoginFormValues {
  email?: string;
  password?: string;
} 

但是 eslint 给出了这样的错误

【问题讨论】:

    标签: reactjs eslint prettier


    【解决方案1】:

    看起来email 不可能是undefined,这似乎是合理的。也很可能password 也不能是undefined。你的类型定义应该是:

    interface LoginFormValues {
      email: string;
      password: string;
    } 
    

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 1970-01-01
      • 2021-11-02
      • 2018-04-05
      • 2021-08-19
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      • 2021-09-30
      相关资源
      最近更新 更多