ts:報錯Could not find a declaration file for module xxx

問題
我們在 typescript 的項目中安裝一些包的話,可能會報錯 Could not find a declaration file for module 'xxx' ,這是因爲這個包可能不是.ts文件而是.js文件,那麼如何解決呢?

解決
如果有這個包的 ts 版本,則

npm install @types/xxx
1
否則,找到根目錄下的 shims-vue-d.ts 文件

declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}
// 加上這個
declare module 'xxx'

如果不在乎外部庫的類型,可以直接設爲

declare module '*'
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章