[英]How to export (and consume) JSDoc comments in typescript NPM packages
I'm trying to get comfortable writing consumable npm packages in typescript. 我试图让自己在打字稿中编写易耗npm软件包。 I have a toy project up at https://www.npmjs.com/package/lynda-copy-course/ , and the project organization is succeeding in:
我在https://www.npmjs.com/package/lynda-copy-course/上有一个玩具项目,项目组织成功完成了:
npm install -g lynda-copy-course
npm install -g lynda-copy-course
后从命令行运行 npm install -s lynda-copy-course
npm install -s lynda-copy-course
后在另一个js / ts项目中工作 The last sticking point is that consuming projects aren't aware of the JSDoc style comments that accompany the source classes and methods. 最后一个难点是,使用中的项目不了解源类和方法随附的JSDoc样式注释 。
How do I configure my project ( package.json
, tsconfig.json
, etc) so that consuming packages can read my JSDoc comments? 如何配置我的项目(
package.json
, tsconfig.json
等),以便使用中的包可以读取我的JSDoc注释?
My current package.json
: 我当前的
package.json
:
{
"name": "lynda-copy-course",
"version": "2.1.7",
"bin": {
"lynda-copy-course": "./bin/lynda-copy-course.js"
},
"main": "./src/index.js",
"types": "./src/index.d.ts",
"dependencies": {
"inquirer": "^3.0.6",
"lodash": "^4.17.4",
"minimist": "^1.2.0",
"ncp": "^2.0.0",
"sqlite3": "^3.1.8"
}
}
My current tsconfig.json
: 我当前的
tsconfig.json
:
{
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"include": [
"src/**/*",
"bin/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
],
"compileOnSave": true,
"typeAcquisition": {
"enable": true
}
}
Github repo at the time of this posting: here . 这篇文章发布时的Github回购: 这里 。
The problem here was in my tsconfig.json
. 这里的问题出在我的
tsconfig.json
。 The compilerOptions.removeComments = true
setting was preventing the JSDoc comments from being inserted into my generated .d.ts
files. .d.ts
compilerOptions.removeComments = true
设置阻止了JSDoc注释插入到我生成的.d.ts
文件中。
For me, this was somewhat unexpected behavior. 对我来说,这有点出乎意料。 Related issue on Typescript's gh page: Preserve JSDocs in *.d.ts files when stripping comments
Typescript gh页上的相关问题: 剥离注释时,在* .d.ts文件中保留JSDocs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.