【问题标题】:TS7016: Could not find a declaration file for module 'vue-timers'TS7016:找不到模块“vue-timers”的声明文件
【发布时间】:2019-10-22 07:33:25
【问题描述】:

我正在尝试在我的应用程序中使用 Vue 插件“Vue Timers”,并在设置了lang="ts 的组件上使用。另一个组件很好地使用了这个插件,但是那个组件没有使用 TypeScript。

编译时出现以下错误:

  [tsl] ERROR in /src/renderer/components/ApplicationStatus.vue.ts(8,36)
        TS7016: Could not find a declaration file for module 'vue-timers'. '/node_modules/vue-timers/index.min.js' implicitly has an 'any' type.

我尝试使用以下行创建shim.d.ts 文件:

declare module 'vue-timers';

但这并没有真正帮助。不知道如何继续。

【问题讨论】:

    标签: typescript vue.js vuejs2


    【解决方案1】:

    .d.ts 文件应位于包含的源路径中(请参阅tsconfig.json 中的include 属性),否则tsc 将无法获取它。对于 Vue CLI 项目,src 目录(以及所有子目录)位于包含的源路径中;你会在那里找到其他.d.ts 文件。将您的shims.d.ts(包含模块声明)放入该目录以解决错误。

    【讨论】:

    • 在 electron 项目中,src "renderer" 中有一个子目录,这是 vue 代码所在的位置。 .d.ts 文件应该在那里?
    • 啊,看起来只是在 tsconfig.json 上添加行就可以了! "include": ["src/**/*.ts", "src/**/*.vue", "*.d.ts"],
    猜你喜欢
    • 2021-07-24
    • 2019-01-09
    • 2020-03-30
    • 2020-03-04
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 2023-02-23
    相关资源
    最近更新 更多