Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘

简介: Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘

在将axios升级到1.2.2版本后,我得到了以下错误:

TS2339: Property ‘Authorization’ does not exist on type ‘AxiosHeaders | Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>’.

Property ‘Authorization’ does not exist on type ‘AxiosHeaders’

The same snippet of code is working on version 1.2.1:

解决方案一:

您可以在以在package.json中尝试"axios": "1.1.3"(不带插入符号)降下版本,重新拉下包,看看是否可以解决问题。

您的团队可能需要计划将代码库依赖项更新到axios的最新版本。

解决方案二:

import axios from 'axios';
axios.interceptors.request.use((request) => {
    request.headers
        ? (request.headers!.Authorization = `Bearer ${token}`)
        : (request.headers = { Authorization: `Bearer ${token}` });
});
目录
相关文章
|
8月前
|
SQL IDE Java
hibernate5 Cannot create TypedQuery for query with more than one return using requested result type
hibernate5 Cannot create TypedQuery for query with more than one return using requested result type
85 0
|
5月前
|
Kubernetes Unix 容器
As the default settings are now deprecated, you should set the endpoint inste
As the default settings are now deprecated, you should set the endpoint inste
|
8月前
|
数据库
Field ‘xxx‘ doesn‘t have a default value
Field ‘xxx‘ doesn‘t have a default value
68 0
|
8月前
|
前端开发 开发者
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
96 1
|
8月前
|
JavaScript API
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
错误代码: 1364 Field ‘password‘ doesn‘t have a default value
错误代码: 1364 Field ‘password‘ doesn‘t have a default value
|
数据库
Field ‘id‘ doesn‘t have a default value
Field ‘id‘ doesn‘t have a default value
178 0
|
JavaScript 前端开发 开发者
Component name “xxx“ should always be multi-word
Component name “xxx“ should always be multi-word
Component name “xxx“ should always be multi-word
|
Java
PropertyReferenceException: No property getAll found for type Users!
Java Spring Boot 2.0连接 MongoDB 4.0时候出错。 抛出来一堆异常信息,最后找到问题根源,解决办法:
3756 0
Caused by: 元素类型为 "package" 的内容必须匹配 "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default-class-ref?,global-results?,globa
在Struts-2.3的配置文件struts.xml中,Caused by: 元素类型为 "package" 的内容必须匹配 "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default-class-ref?,global-results?,global-exception-mappings?,action*)"。
1313 0

热门文章

最新文章