最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I import third party package without d.ts file? - Stack Overflow

programmeradmin0浏览0评论

I'm studying typescript. I get some errors when I tried import some packages. I was check in node_modules folder, it downloaded but this don't have a *.d.ts file. How can I import them?

I'm studying typescript. I get some errors when I tried import some packages. I was check in node_modules folder, it downloaded but this don't have a *.d.ts file. How can I import them?

Share Improve this question edited Apr 2, 2019 at 6:16 Talha Rahman 7284 gold badges12 silver badges27 bronze badges asked Sep 17, 2018 at 16:03 Hiep NguyenHiep Nguyen 3051 gold badge8 silver badges18 bronze badges 1
  • Possible duplicate of Could not find a declaration file for module 'module-name'. '/path/to/module-name.js' implicitly has an 'any' type – tony19 Commented Sep 17, 2018 at 16:15
Add a ment  | 

2 Answers 2

Reset to default 5

You can put all your custom imports in my own file. For instance, create shared/types/imports.d.ts file.

declare module "vue-multiselect";
declare module "vue-notification";

And in your tsconfig.json file include those imports with the following lines.

"typeRoots": [
  "node_modules/@types", "VueApp/shared/types"
],

And of course, restart your IDE because sometimes it doesn't detect the change immediately.

Make modules for them. Make sure to include the path to your types directory locally:

declare module 'vue-cookie' {

}

All module declarations need to be in their own, separate files. For instance, the vue-cookie file should be named something to the effect of vue-cookie.d.ts.

Also, as you go through the module, you can start typing it correctly.

发布评论

评论列表(0)

  1. 暂无评论