removeComments documentation comments removed persistentDocumentation
In the current version of TypeScript, when removeComments is set to true, it removes all comments except copy-right header comments beginning with /*!. This is very useful, but I think it can be refined.
In my JavaScript editors, comments beginning with /** are treated as a kind of JSDoc comment, which describes the function directly below it. If removeComments is set to true, then it also removes these documentation comments which can be VERY useful. So, I want to propose a change to this setting. Everything says the same, but when "removeComments": true is combined with something like "persistentDocumentation": true, the compiler removes all comments except for comments beginning with either /*! OR /**.
My current approach includes just leaving removeComments off. This is not ideal, as there are many comments that are for devs and devs only, but there are also many JS documentation comments that are meant for the person using the library.
With this suggestion, no changes would be made to any current compiler settings. The user must know of this feature and change their compiler settings. This feature would only benefit the TS community.
/*!
Super-awesome legal statement
*/
// The adding function
/**
* Returns the sum of two addends
* @param number1 The first addend
* @param number2 The second addend
*/
export function add(number1: number, number2: number): number {
return number1 + number2; // Return the number
}
/*
Continue to build out this library.
Future additions:
Subtraction
Multiplication
Exponents
Factorials
*/
We all know what just removeComments would do, so the same but with persistentDocumentation:
/*!
Super-awesome legal statement
*/
export function add(number1, number2) {
return number1 + number2;
}
/*!
Super-awesome legal statement
*/
/**
* Returns the sum of two addends
* @param number1 The first addend
* @param number2 The second addend
*/
export function add(number1: number, number2: number): number;
Very handy indeed!
Instead of this, which would be ideal, something could be set up with the ts-to-js map file that can be generated, which maps the documentation comments to the compiled js file, but as mentioned, this is... less than ideal. Also, I can imagine it would be harder to code.
I just wanted to throw this out there just in case.
My suggestion meets these guidelines:
To add to the suggestion above, I also think there should be a distinction between regular comments and jsdocs, but another useful distinction would be *.js vs. *.d.ts files.
Or to be clearer, my suggestion is to have a mode that:
*.d.ts - keeps jsdocs/license comments. Removes all other comments.*.js - keeps just the license comment.@AviVahl I think that's a very good idea. Most editors, like VS Code, take into consideration a file's map and definitions. It makes sense, too - the file's definitions would be the perfect place for the jsdoc comments.
I've edited my suggestion to include yours as well.
Not to mention that, without removeComments, the TypeScript compiler already includes jsdoc comments in the definitions file.
Unless there's an alternate spelling that I couldn't find, "persistent" is the correct spelling.
I want to "removeComments" to minify the JS file but keep comments at declaration file. Happy to see this feature comes true.
Why would removeComments minify the JS file? It's for removing comments only. Also, please don't open up the bucket of worms that is TypeScript auto-minifying when a file compiles...
Why would
removeCommentsminify the JS file? It's for removing comments only. Also, please don't open up the bucket of worms that is TypeScript auto-minifying when a file compiles...
Cause comments are about half of total in my file. I know it's not minifying the file. Sorry for the wrong word choosing
Ahh. Alright!
Most helpful comment
Unless there's an alternate spelling that I couldn't find, "persistent" is the correct spelling.