简体   繁体   English

与声明文件中的npm软件包捆绑在一起的类型

[英]Bundle types with npm package from declaration files

I am trying to create my first npm module, here is the source code: 我正在尝试创建我的第一个npm模块,这是源代码:

https://github.com/balazsorban44/use-form https://github.com/balazsorban44/use-form

I would like to use semantic-release and write my code in .js files, but I also include some type declaration files for a better experience in IDEs like VSCode. 我想使用semantic-release并将代码写在.js文件中,但是我还包括一些类型声明文件,以便在VSCode等IDE中获得更好的体验。 (Note, I am learning TypeScript as well) (注意,我也在学习TypeScript)

I found a way to bundle my code and even publish it to npm with semantic-release, but when I try to import that module into a React project, I don't get any suggestions from the IDE, probably because I missed a (or a few) step(s)? 我找到了一种方法来捆绑我的代码,甚至可以通过语义发布将其发布到npm,但是当我尝试将该模块导入React项目时,我没有从IDE中得到任何建议,可能是因为我错过了(或几步? How can I include the .d.ts files, so my IDE will pick up the type declarations? 如何包含.d.ts文件,以便我的IDE可以选择类型声明?

I figured out, thanks to the help I got on Twitter! 我想通了,这要归功于我在Twitter上获得的帮助!

In package.json I had to add my typings folder to the files to be published on NPM: package.json我必须将我的类型文件夹添加到要在NPM上发布的文件中:

https://github.com/balazsorban44/use-form/blob/c4e7efdbb7ca58a3ad48516e3ec63b4a71b72446/package.json#L46-L49 https://github.com/balazsorban44/use-form/blob/c4e7efdbb7ca58a3ad48516e3ec63b4a71b72446/package.json#L46-L49

Apart from that, these lines may play an important role also: 除此之外,这些路线还可能发挥重要作用:

https://github.com/balazsorban44/use-form/blob/c4e7efdbb7ca58a3ad48516e3ec63b4a71b72446/package.json#L18-L20 https://github.com/balazsorban44/use-form/blob/c4e7efdbb7ca58a3ad48516e3ec63b4a71b72446/package.json#L18-L20

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM