夏季
我添加了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/