[英]How to avoid Flow-type error on ES6 arrow function
我无法解决Flow类型警告
检查此代码块时
export const login = (email: string, password: string) => ({
type: types.LOGIN,
responseTypes: [types.LOGIN_SUCCESS, types.LOGIN_FAILURE],
promise: (client: Client) => client.post('/auth/sign_in', { email, password }),
});
我收到了警告
error单个函数参数周围的意外括号,其主体没有花括号arrow-parens
但是,当我删除括号(client: Client)
,我收到错误
模块构建失败:SyntaxError:意外的令牌
在client
后的冒号。
将功能更改为以下内容
export const login = (email: string, password: string) => ({
type: types.LOGIN,
responseTypes: [types.LOGIN_SUCCESS, types.LOGIN_FAILURE],
promise: (client: Client) => { return client.post('/auth/sign_in', { email, password }); },
});
返回以下警告:
error包含箭头体箭头体样式的意外块语句
我对修复此警告的正确语法有点困惑。 谢谢。
您得到的错误来自eslint arrow-parens规则,而不是来自flow。
您可以通过更改eslint配置或尝试ES6方法语法来解决此问题:
promise(client: Client) {
return client.post('/auth/sign_in', { email, password })
},
我认为这个问题出现在你的第一个函数中,你将括号中的正文包裹在括号中。
export const login = (email: string, password: string) => {
type: types.LOGIN,
responseTypes: [
types.LOGIN_SUCCESS, types.LOGIN_FAILURE
],
promise: (client: Client) => client.post('/auth/sign_in', { email, password }),
};
你也可以用这种方式编写它(不使用单个表达式的简写。
export const login = (email: string, password: string) => {
type: types.LOGIN,
responseTypes: [
types.LOGIN_SUCCESS, types.LOGIN_FAILURE
],
promise: (client: Client) => { return client.post('/auth/sign_in', { email, password }); },
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.