Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

ts引用axios后,axios报错

test.ts:

import axios from 'axios'
console.log(axios.get('https://www.xxx.com'))

image.png

报错:TS2339: Property 'get' does not exist on type 'typeof Axios'.

虽然可以这样解决,但是每次都要类型断言一次太麻烦了

import axios from 'axios'
console.log((axios as any).get('https://www.xxx.com'))

求大神指点指点


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

axios是自带type声明的
问题应该是ide没有检索到axios声明文件。
先删除整个node_modules文件夹,在npm install试试?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...