[英]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.