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}` });
});
目录
相关文章
|
4月前
|
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
23 0
|
29天前
|
数据库
Field ‘xxx‘ doesn‘t have a default value
Field ‘xxx‘ doesn‘t have a default value
15 0
|
5月前
|
JavaScript API
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
|
5月前
|
前端开发 开发者
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
50 1
|
8月前
|
JavaScript
Error TS6138 - Property xxxx is declared but its value is never read
Error TS6138 - Property xxxx is declared but its value is never read
53 0
|
11月前
|
SQL
错误代码: 1364 Field ‘password‘ doesn‘t have a default value
错误代码: 1364 Field ‘password‘ doesn‘t have a default value
|
11月前
|
数据库
Field ‘id‘ doesn‘t have a default value
Field ‘id‘ doesn‘t have a default value
121 0
Property ngOnInit does not exist on type VisibleFocusDirective
Property ngOnInit does not exist on type VisibleFocusDirective
Property ngOnInit does not exist on type VisibleFocusDirective
How to enable multiple text type for Product
Created by Jerry Wang, last modified on Oct 31, 2014
105 0
How to enable multiple text type for Product
|
Java
PropertyReferenceException: No property getAll found for type Users!
Java Spring Boot 2.0连接 MongoDB 4.0时候出错。 抛出来一堆异常信息,最后找到问题根源,解决办法:
3679 0