Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Render Comment or Text

What is the Typescript syntax (if it exists) to include comments or text into the rendered js file?

Currently you can include all comments or no comments, but nothing in between.

//this doesn't work
/*this doesn't work either*/

I'm trying to:

  • Include license information with any js libraries I might use.
  • Instruct rendered js files to include separate js file paths for testing like with Jasmine and Resharper . /// <..reference path="myTestable.js"/>

This is how to include or exclude ALL comments in the rendered js files. I want to do this with syntax selectively throughout my typescript code though, not globally on or off

Tools > Options > WebEssestials > Typescript > Keep comments: true | false

My current guess is that it cannot be done but maybe this post will help others come to the same conclusion more quickly, or when/if it is possible, get the answer.

I'm trying whatever I find at the typescript playground

Thanks.

like image 274
TheDev6 Avatar asked Sep 02 '26 04:09

TheDev6


1 Answers

There is indeed only "on" or "off" for comment preservation. Adding some sort of metalanguage to let you decide which comments to keep and which to omit isn't a feature we're likely to add (because library developers are ideally shipping .d.ts files which would automatically have implementation comments removed, that more common scenario is basically already covered).

You could pretty reasonably use something like esprima to implement a post-compile step that conformed to the exact behavior you wanted.

like image 105
Ryan Cavanaugh Avatar answered Sep 03 '26 19:09

Ryan Cavanaugh