【问题标题】:Could not find a declaration file for third party modules - how to declare and resolve these errors找不到第三方模块的声明文件 - 如何声明和解决这些错误
【发布时间】:2018-10-25 21:00:44
【问题描述】:

我正在开发一个带有 typescript 的项目(使用 vue cli 3.0 生成)。

当我导入第三方模块时,出现如下错误:

Could not find a declaration file for module 'vue-slider-component'. 
'/home/wahid/Development/tealvalley-app/node_modules/vue-slider- 
component/dist/index.js' implicitly has an 'any' type.

解决此类问题的正确方法是什么? @types 包中没有定义类型,所以如果我要自己定义它们,我将它保存在哪里?

【问题讨论】:

    标签: typescript vuejs2 typescript-typings vue-cli


    【解决方案1】:

    解决此类问题的正确方法是什么?

    创建一个文件vendor.d.ts,其中包含:

    declare module 'vue-slider-component';
    

    【讨论】:

      【解决方案2】:

      这个错误是因为在 JavaScript 中生成了 vue-slider-component。

      为了避免这个问题,我只是用标准 require() 替换它:

      const vue-slider-component= require('vue-slider-component');
      // import { vue-slider-component} from 'vue-slider-component'
      

      谢谢:slight_smile:

      【讨论】:

        猜你喜欢
        • 2020-07-30
        • 2019-11-17
        • 2017-08-13
        • 1970-01-01
        • 2017-10-18
        • 2019-10-14
        • 2021-01-02
        • 2019-04-29
        相关资源
        最近更新 更多