gpt4 book ai didi

javascript - 如何避免 ES6 箭头函数的 Flow-type 错误

转载 作者:行者123 更新时间:2023-11-30 11:41:34 24 4
gpt4 key购买 nike

我无法解决流式警告

当检查此代码块时

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 Unexpected parentheses around single function argument having a body with no curly braces arrow-parens

但是,当我删除 (client: Client) 周围的括号时,我收到错误

Module build failed: SyntaxError: Unexpected token

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 Unexpected block statement surrounding arrow body arrow-body-style

我对修复此警告的正确语法感到有点困惑。谢谢。

最佳答案

您得到的错误来自 eslint arrow-parens规则,而不是来自流量。

您可以通过更改 eslint 配置或尝试 ES6 method syntax 来解决它:

promise(client: Client) {
return client.post('/auth/sign_in', { email, password })
},

关于javascript - 如何避免 ES6 箭头函数的 Flow-type 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42450837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com