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}` });
});
目录
相关文章
|
6月前
|
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
74 0
|
3月前
|
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
|
6月前
|
数据库
Field ‘xxx‘ doesn‘t have a default value
Field ‘xxx‘ doesn‘t have a default value
49 0
|
6月前
|
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
166 0
|
Java
PropertyReferenceException: No property getAll found for type Users!
Java Spring Boot 2.0连接 MongoDB 4.0时候出错。 抛出来一堆异常信息,最后找到问题根源,解决办法:
3745 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*)"。
1307 0
|
物联网 测试技术 索引
[20180609]Wrong Results with IOT, Added Column and Secondary Index2.txt
[20180609]Wrong Results with IOT, Added Column and Secondary Index2.txt --//链接:http://db-oriented.
1141 0
|
物联网 测试技术 索引
[20180608]Wrong Results with IOT, Added Column and Secondary Index.txt
[20180608]Wrong Results with IOT, Added Column and Secondary Index.txt --//链接:http://db-oriented.
1085 0