TS2345:'string | undefined' 类型的参数不可分配给 'string' 类型的参数。类型 'undefined' 不可分配给类型 'string'
TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'
我定义的类型如下
interface LoginFormValues {
email?: string;
password?: string;
}
但是 eslint 给出了这样的错误
貌似email
不可能是undefined
,好像也有道理。也有可能 password
也不能是 undefined
。您的类型定义可能应该是:
interface LoginFormValues {
email: string;
password: string;
}
我定义的类型如下
interface LoginFormValues {
email?: string;
password?: string;
}
但是 eslint 给出了这样的错误
貌似email
不可能是undefined
,好像也有道理。也有可能 password
也不能是 undefined
。您的类型定义可能应该是:
interface LoginFormValues {
email: string;
password: string;
}