I looked high and low for this issue having already been brought up OR an option in the typescript compiler to control this behavior.
Basically, my code has JSDocs all over it explaining how everything works, but when the typescript compiler generates the d.ts files ALL the JSDocs are stripped away. I get definition files that describe the classes, methods, and interfaces but nothing else. No documentation.
I would like to see an option to tell the TS compiler to leave the comments in the definition files it generates.
Do you have removeComments enabled in your tsconfig.json file - seen here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html?
I can not get this to reproduce locally.. i copied your file locally, and ran the same command, and no luck. something else is going on here, can you share a self-contained repro project?
Here is what i see. file contents redacted for brevity.
c:\test\13209>Tree /F
C:.
└───src
a.ts
c:\test\13209>type src\a.ts
import { TSMap } from "typescript-map";
import { TSPromise } from "typescript-promise";
import { SomeSQLMemDB } from "./memory-db";
/**
* This is the format used for actions and views
*
* @export
* @interface ActionOrView
*/
export interface ActionOrView {
name: string;
args?: Array<string>;
call: (args?: Object) => TSPromise<any>;
}
c:\test\13209>tsc -v
Version 2.1.5-insiders.20161229
c:\test\13209>tsc --stripInternal -d --declarationDir "." -t "ES5" --rootDir "src" src\a.ts
src/a.ts(1,23): error TS2307: Cannot find module 'typescript-map'.
src/a.ts(2,27): error TS2307: Cannot find module 'typescript-promise'.
src/a.ts(3,30): error TS2307: Cannot find module './memory-db'.
c:\test\13209>type a.d.ts
import { TSPromise } from "typescript-promise";
/**
* This is the format used for actions and views
*
* @export
* @interface ActionOrView
*/
export interface ActionOrView {
name: string;
args?: Array<string>;
call: (args?: Object) => TSPromise<any>;
}
Yes, the project where the comments aren't being exported is here:
https://github.com/ClickSimply/Some-SQL
Just run npm install && npm run build on the repo.
Yes, but if you look at the build.sh command you'll see that I'm explicitly passing command line arguments to TSC instead of telling to use the config file. My TSConfig doesn't have declarations export enabled, so if I'm getting tsd files it shouldn't be using the tsconfig.
Maybe that's the confusing part? I want to build the tsd files with comments, but the final JS file shouldn't have them. Seems like a pretty common use case to me.
Just take a look at the bin/build.sh file and you'll see what I mean.
Anyway I got it working now. With the repo above, this command generated tsd files without comments:
./node_modules/.bin/tsc --stripInternal -d --declarationDir "." -t "ES5" --rootDir "src"
But when I changed the build command to this it worked:
./node_modules/.bin/tsc --stripInternal -d --declarationDir "." -t "ES5" --rootDir "./src" src/index.ts
Working on recreating this behavior in a cleaner environment.
if you call tsc with no files or no --p, the tsconfig.json in the current folder is used. so your command
./node_modules/.bin/tsc --stripInternal -d --declarationDir "." -t "ES5" --rootDir "src"
is actually using the tsconfig.json to build...
the other one specifies a list of files, i.e. src/index.ts. and thus the tsconfig.json is not used.
Ah, I don't think I was expecting the compiler to merge my CLI commands with the TSConfig stuff. Thanks for your help.
@ClickSimply so you can just pass --removeComments false to tsc and everything will work 😃
Most helpful comment
if you call
tscwith no files or no--p, the tsconfig.json in the current folder is used. so your commandis actually using the tsconfig.json to build...
the other one specifies a list of files, i.e.
src/index.ts. and thus the tsconfig.json is not used.