Including TypeScript comments in generated JavaScript

Just a quick one for those needing typescript comments to be included in generated JavaScript files.

The TypeScript compiler has the –c option to included comments, but this option is not available when working with Visual Studio.

The simple solution is to modify the .csproj project file and included –c in the call to the TypeScript compiler.

  • Right-click on your project file in Visual Studio, and click Unload Project.
  • Right-click again on the project file, and select Edit <your project name>.csproj

This will bring up the xml project file in edit mode.

Scroll down to the bottom of the file, and locate the following snippet:

  <Target Name="BeforeBuild">
    <Exec Command="&amp;quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&amp;quot; @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
  </Target>

Now add a –c after the tsc&amp;quot; and before the @(TypeScriptCompile as follows:

From:
\TypeScript.8.0.0\tsc&quot; @(TypeScriptCompile ->

To:

\TypeScript.8.0.0\tsc&quot; -c @(TypeScriptCompile ->

Save the project file, and re-load it.

TypeScript will now include all comments within a .ts file into the generated .js file.

Have fun,

– Blorkfish

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: