我如何在我的 auth.tsx 文件中使用打字稿文件
How can i use typescript file on my auth.tsx file
我的问题会有点简单,但我是 typescript 的新手,所以我在编码时遇到了问题。
我有一个表单结构,这个表单在后端使用 jwt 令牌。当然,我必须向这个 API 提出请求,所以我在 action 文件下创建了一个名为 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
});
}
};
and then i get this error:
The 'new_password' parameter has an implicit type 'any'.
我在下面列出的变量中也遇到了这个错误。
uid, token, email, new_password, password, dispatch.
如何在此文件中使用打字稿
谁能帮忙。谢谢
在打字稿中,函数参数需要类型。这强制了什么样的东西可以传递给函数,并让你知道如何在函数内部使用那个东西。
例如:
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) => {
//...
}
我的问题会有点简单,但我是 typescript 的新手,所以我在编码时遇到了问题。
我有一个表单结构,这个表单在后端使用 jwt 令牌。当然,我必须向这个 API 提出请求,所以我在 action 文件下创建了一个名为 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
});
}
};
and then i get this error:
The 'new_password' parameter has an implicit type 'any'.
我在下面列出的变量中也遇到了这个错误。
uid, token, email, new_password, password, dispatch.
如何在此文件中使用打字稿 谁能帮忙。谢谢
在打字稿中,函数参数需要类型。这强制了什么样的东西可以传递给函数,并让你知道如何在函数内部使用那个东西。
例如:
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) => {
//...
}