I want to publish a npm package written in Typescript.
(我想发布一个用Typescript编写的npm包。)
As far as typing goes, my current approach is to simply let tsc
generate a .d.ts
for every file, via the delaration:true
setting.
(就键入而言,我当前的方法是通过delaration:true
设置让tsc
为每个文件生成一个.d.ts
。)
I've heard you need a single index.d.ts (which I have emitted once with dts-generator, and it didn't seem to provide any typing assistance to IDEs), though the typescript's native map seem to work okayish. (我听说你需要一个单一的 index.d.ts(这是我一次发射与DTS-发生器,它似乎并没有提供对IDE的任何类型的援助),虽然打字稿的本地地图似乎工作okayish。)
I tried importing all public APIs into src/index.ts
and exporting it out, then setting the main
in package.json
to dist/index.js
, however it seems that IDEs prefer to dig deep into my package's files (for example, on typing MainClass
WebStorm suggests my-package/dist/MainClass
and my-package/dist
), rather than simply import the package itself, such as import {MainClass} from "myPackage"
.
(我尝试将所有公共API导入src/index.ts
并将其导出,然后将package.json
的main
设置为dist/index.js
,但是IDE似乎更喜欢深入研究我的包文件(例如,键入MainClass
WebStorm建议使用my-package/dist/MainClass
和my-package/dist
),而不是简单地导入包本身,例如import {MainClass} from "myPackage"
。)
The latter does work (probably due to everything being re-exported from index/index.js
, nevertheless the fact that IDEs show such suggestions makes me think something's wrong with my package's structure. (后者确实可以工作 (可能是由于所有内容都从index/index.js
重新导出,但是IDE显示了这样的建议的事实使我认为我的包结构有问题。)
Here is the link to the repo.
(这是回购的链接。)
ask by John Smith translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…