Request for more fine grained control of which comments are preserved (I don't want to preserve references to typings)

Topics: General
May 3, 2013 at 8:31 PM
Hi Guys,

I've got a problem with TypeScripts "preserve comments" mechanism.

In my existing project I'm using Cassette to serve up my JavaScript files. If you haven't heard about Cassette you can read up on it here:

In particular I'm taking advantage of the ability to get Cassette to serve scripts in dependency order through the use of reference comments at the top of JavaScript files that look like this:

// @reference other.js

or this:

/// <reference path="other.js" />

(nb if interested you can find more details on how that works here: )

Because I want to continue to take advantage of this feature of Cassette working with the JavaScript generated by the TypeScript compiler I was intending to enable the "preserve comments" option. This would work fine with me making use of the "// @reference other.js" style references in my TypeScript. However, to my frustration the typing file comments are * also * being preserved. This seems a little strange to me since these aren't strictly speaking comments, more compiler directives masquerading as comments.

So my JavaScript ends up with references to the typings files like this:

/// <reference path="jquery.d.ts" />

Just to demonstrate, TypeScript like this:
// @reference jQuery-1.8.2.js
/// <reference path="jquery.d.ts" />

// Module
module Shapes {

    // Class
    export class Point implements IPoint {
        // Constructor
        constructor (public x: number, public y: number) { }

        // Instance member
        getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }

        // Static member
        static origin = new Point(0, 0);


// Interface
interface IPoint {
    getDist(): number;

// Local variables
var p: IPoint = new Shapes.Point(3, 4);
var dist = p.getDist();
Will generate JavaScript like this:
// @reference jQuery-1.8.2.js
/// <reference path="jquery.d.ts" />
// Module
var Shapes;
(function (Shapes) {
    // Class
    var Point = (function () {
        // Constructor
        function Point(x, y) {
            this.x = x;
            this.y = y;
        Point.prototype.getDist = // Instance member
        function () {
            return Math.sqrt(this.x * this.x + this.y * this.y);
        Point.origin = new Point(0, 0);
        return Point;
    Shapes.Point = Point;    
})(Shapes || (Shapes = {}));
// Local variables
var p = new Shapes.Point(3, 4);
var dist = p.getDist();
As you can see this has the unfortunate side effect of serving up the typing files which will in turn make Cassette serve up the TypeScript typings files with the JavaScript. And that stops me from making use of TypeScript in the way I would hope.

Would it be possible to introduce more fine grained control over what comments should be preserved?

Perhaps it would be possible to include a block syntax that, if present would indicate that a set of comments should not be preserved? Maybe something as simple as this would suffice?:
/// <reference path="jquery.d.ts" />
Alternatively, would it be possible to introduce a compiler option which preserved comments but not comments that are actually typing references? Either would work for me...
May 3, 2013 at 10:58 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 3, 2013 at 10:59 PM
I think this is just a bug. There's no reason to emit the /// references into the JavaScript anyway. I've created a work item for you to track the issue
May 7, 2013 at 8:30 AM
Thanks Dan - I've voted for the work item. Hopefully it'll get picked up along the way.