typescript - 找不到模块 'vue2-timepicker' 的声明文件

标签 typescript vue.js nuxt.js

夏季

我添加了vue2-timepicker在我的 Typescript/Nuxt.js 应用程序中。
但导入vue2-timepicker

失败
import timepicker from 'vue2-timepicker'
Could not find a declaration file for module 'vue2-timepicker'.
'/home/jpskgc/sample-nuxt/node_modules/vue2-timepicker/dist/VueTimepicker.umd.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/vue2-timepicker` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue2-timepicker';`

我想解决这个问题。

描述我尝试过的操作。

我尝试添加@types/vue2-timepicker,但它不存在。

❯ yarn add @types/vue2-timepicker
yarn add v1.22.17
[1/4] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/@types%2fvue2-timepicke: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/home/jpskgc/sample-nuxt/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

显示一些代码。

这是实际的存储库。请检查。
https://github.com/jpskgc/nuxt-sample/blob/main/components/registration-form/index.vue

最佳答案

由于包的类型不可用,请尝试忽略它们。

// @ts-ignore

导入的包可以正常工作。

其他选项是创建虚拟 .d.ts 定义,该定义将允许从模块导入任何内容。

关于typescript - 找不到模块 'vue2-timepicker' 的声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70227235/

相关文章:

javascript - 使用 Jest 测试 NUXT.js 和 Vue.js 应用程序。获取 '[vuex] module namespace not found in mapState()' 和 '[vuex] unknown action type'

javascript - @types/react/index\"' 没有默认导出。",

typescript - 是否可以循环遍历一个接口(interface)中的所有对象来获取键和值?

vue.js - 如何在整个 Electron 应用程序中访问 `process`?

checkbox - 拦截 VueJS 中的复选框更改事件

javascript - nuxt 生成 : Failed to execute 'appendChild' on 'Node'

service-worker - 使用 nuxt 和 @nuxtjs/pwa 的网站不缓存谷歌字体

typescript - 如何使用函数返回的类作为 TypeScript 中的类型?

javascript - Angular 7 : How to Use croppie or any other cropper

javascript - 如何在创建 VueJS 实例之前*加载外部托管 (CDN) JS 库?