Reputation: 621
I'm trying to get comfortable writing consumable npm packages in typescript. I have a toy project up at https://www.npmjs.com/package/lynda-copy-course/, and the project organization is succeeding in:
npm install -g lynda-copy-course
npm install -s lynda-copy-course
The last sticking point is that consuming projects aren't aware of the JSDoc style comments that accompany the source classes and methods.
How do I configure my project (package.json
, tsconfig.json
, etc) so that consuming packages can read my JSDoc comments?
My current 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
:
{
"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.
Upvotes: 2
Views: 1885
Reputation: 621
The problem here was in my tsconfig.json
. The compilerOptions.removeComments = true
setting was preventing the JSDoc comments from being inserted into my generated .d.ts
files.
For me, this was somewhat unexpected behavior. Related issue on Typescript's gh page: Preserve JSDocs in *.d.ts files when stripping comments
Upvotes: 5