Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

typescript - 用Typescript编写的NPM软件包-定义面向公众的API(A NPM package written in Typescript - defining the public-facing API)

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.jsonmain设置为dist/index.js ,但是IDE似乎更喜欢深入研究我的包文件(例如,键入MainClass WebStorm建议使用my-package/dist/MainClassmy-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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...