我的問題會有點簡單,但我是打字稿的新手,所以我在編碼時遇到了麻煩。
我有一個表單結構,這個表單在后端使用 jwt 令牌。自然,我必須向這個 API 發出請求,所以我在操作檔案下創建了一個名為 auth.tsx 的檔案并撰寫了必要的代碼,但是由于我的系統上有打字稿,我在某些資料型別中遇到了任何錯誤。
這是我遇到錯誤的資料型別和變數的示例
export const reset_password_confirm = (uid, token, new_password, re_new_password) => async dispatch => {
const config = {
headers: {
'Content-Type': 'application/json'
}
};
const body = JSON.stringify({ uid, token, new_password, re_new_password });
try {
await axios.post(`${process.env.REACT_APP_API_URL}/auth/users/reset_password_confirm/`, body, config);
dispatch({
type: PASSWORD_RESET_CONFIRM_SUCCESS
});
} catch (err) {
dispatch({
type: PASSWORD_RESET_CONFIRM_FAIL
});
}
};
然后我收到此錯誤:
The 'new_password' parameter has an implicit type 'any'.
我也在下面列出的變數中收到此錯誤。
uid, token, email, new_password, password, dispatch.
我如何在此檔案中使用打字稿,請任何人幫忙。謝謝
uj5u.com熱心網友回復:
在打字稿函式引數需要型別。這強制執行可以傳遞給函式的東西型別,并讓您知道如何在函式內部使用該東西。
例如:
import { DispatchOrSomething } from 'redux-or-whatever-lib'
export const reset_password_confirm = (
uid: number,
token: string,
new_password: string,
re_new_password: string
) => async (dispatch: DispatchOrSomething) => {
//...
}
例如,看看這個游樂場
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/342375.html
標籤:javascript 反应 打字稿 jsx
