简体   繁体   English

如何在没有d.ts文件的情况下导入第三方软件包?

[英]How can I import third party package without d.ts file?

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. 我正在检查node_modules文件夹,它已下载,但是没有*.d.ts文件。 How can I import them? 如何导入它们?

在此处输入图片说明

You can put all your custom imports in my own file. 您可以将所有自定义导入内容放入我自己的文件中。 For instance, create shared/types/imports.d.ts file. 例如,创建shared / types / imports.d.ts文件。

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

And in your tsconfig.json file include those imports with the following lines. 并在您的tsconfig.json文件中包括带有以下行的那些导入。

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

And of course, restart your IDE because sometimes it doesn't detect the change immediately. 当然,请重新启动IDE,因为有时它不会立即检测到更改。

Make modules for them. 为他们制作模块。 Make sure to include the path to your types directory locally: 确保在本地包含您的types目录的路径:

declare module 'vue-cookie' {

}

All module declarations need to be in their own, separate files. 所有module declarations必须位于各自独立的文件中。 For instance, the vue-cookie file should be named something to the effect of vue-cookie.d.ts . 例如,应将vue-cookie文件命名为vue-cookie.d.ts

Also, as you go through the module, you can start typing it correctly. 另外,在浏览模块时,您可以开始正确键入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不创建自定义.d.ts文件或关闭整个项目的noimplicitany的情况下导入外部库? - How can I import an external library without creating a custom .d.ts file OR turning noimplicitany off for my entire project? 如何导入一个 js 模块。 (没有任何声明文件(d.ts)) - How to import a js Module as any. (Without any declaration file (d.ts)) 从.d.ts文件导入打字稿 - Typescript import from .d.ts file 我可以在 js 中添加对在线 .d.ts 文件的引用吗? - Can I add in js reference to an online .d.ts file? 如何在本地 javascript 函数中使用 .d.ts - How can I use .d.ts with in local javascript function 有没有一种方法可以在TypeScript上使用不带d.ts定义的npm软件包 - Is there a way to use a npm package without d.ts definition on TypeScript 打字稿为npm包制作一个简单的d.ts文件 - typescript make a simple d.ts file for npm package Webpack 抱怨打字稿定义文件导入 - 除非我添加一个 `d.ts` 结尾 - Webpack complains of a typescript definition file import - unless I add a `d.ts` ending 如何创建一个`d.ts`文件来导入一个非模块的外部npm库 - how to create a `d.ts` file to import an external npm lib that is not a module 如何防止TypeScript在输出中包含.d.ts导入? - How to prevent TypeScript from including .d.ts import in the output?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM