【发布时间】:2022-08-17 11:47:36
【问题描述】:
当我尝试执行以下代码时,我不断收到此错误。基本上,它接受给定的刷新令牌并将带有 URLSearchParams 的 POST 请求发送到 URL。但由于某种原因,URLSearch 参数不断抛出错误。
代码
const getAccessToken = async () => {
const response = await fetch(TOKEN_ENDPOINT, {
method: \'POST\',
headers: {
Authorization: `Basic ${basic}`,
\'Content-Type\': \'application/x-www-form-urlencoded\',
},
body: new URLSearchParams({
grant_type: \'refresh_token\',
refresh_token,
}),
})
return response.json()
}
其中refresh_token 是由环境变量定义的常量。
错误
Argument of type \'{ grant_type: string; refresh_token: string | undefined; }\' is not assignable to parameter of type \'string | string[][] | Record<string, string> | URLSearchParams | undefined\'.
Type \'{ grant_type: string; refresh_token: string | undefined; }\' is not assignable to type \'undefined\'.ts(2345)
标签: node.js typescript next.js request typescript2.0