类型“AxiosHeaders|Partial<RawAxiosHeaders&MethodsHeaders&CommonHeaders>”上不存在属性“Authorization”

我正在尝试使用TypeScript通过JWT身份验证配置Axios("axios": "^1.2.2")。我在某些计算机上遇到TS2339错误
TS2339:属性“Authorization”在类型“AxiosHeaders|Partial<RawAxiosHeaders&MethodsHeaders&CommonHeaders>”上不存在。类型“AxiosHeaders”上不存在属性“Authorization”。

    • 最新的 axios 是版本 1.2.2 ,如果强行在请求拦截器中设置**Authorization **会报错
    • 解决方案:
    • 使用上面的代码的话,要将 axios 的版本降级到 1.1.3版本
    • 不想降版本则要调用 set 方法

通过使用上面的set方法就可以解决报错问题.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
类型“((config: AxiosRequestConfig<any>) => AxiosRequestConfig<any>) | undefined”的参数不能赋给类型“((value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>) | null | undefined”的参数。 不能类型“(config: AxiosRequestConfig<any>) => AxiosRequestConfig<any>”分配给类型“(value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>”。 不能类型AxiosRequestConfig<any>”分配给类型“InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>”。 不能类型AxiosRequestConfig<any>”分配给类型“InternalAxiosRequestConfig<any>”。 属性headers”的类型不兼容。 不能类型AxiosHeaders | (Partial<RawAxiosHeaders & { Accept: AxiosHeaderValue; "Content-Length": AxiosHeaderValue; "User-Agent": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; Authorization: AxiosHeaderValue; } & { ...; }> & Partial<...>) | undefined”分配给类型AxiosRequestHeaders”。 不能类型“undefined”分配给类型AxiosRequestHeaders”。 不能类型“undefined”分配给类型Partial<RawAxiosHeaders & { Accept: AxiosHeaderValue; "Content-Length": AxiosHeaderValue; "User-Agent": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; Authorization: AxiosHeaderValue; } & { ...; }>”。ts(2345) (property) HRequestInterceptors<AxiosResponse<any, any>>.requestInterceptors?: ((config: AxiosRequestConfig<any>) => AxiosRequestConfig<any>) | undefined
07-13

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值