10

I am learning typescript and I noticed that the compiled javascript has a comment for every class that looks like this: /** @class */

Example:

var Student = /** @class */ (function () {
    function Student(firstName, middleInitial, lastName) {
        this.firstName = firstName;
        this.middleInitial = middleInitial;
        this.lastName = lastName;
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
    return Student;
}());

My question is does this comment have any functional value or is it just syntactical sugar? Also, If it does have a function, what is the function?

Dallas Caley
  • 4,027
  • 5
  • 33
  • 53
  • Thanks all, i wish i could mark every answer here as correct because they all are, but i'm choosing Ryan's because I think it has the most functional value (also because I was unaware of that aspect, the documentation thing was fairly obvious) – Dallas Caley Dec 27 '17 at 21:36

3 Answers3

20

This is emitted so that minifiers can remove unused classes. To minifiers, the class setup looks like something with potentially important side effects, so this comment indicates to them that the code block can be safely removed if the rest of the code doesn't refer to it.

Ryan Cavanaugh
  • 164,706
  • 43
  • 239
  • 219
5

It's outputting a JSDoc comment in case you want to document your code: http://usejsdoc.org/tags-class.html.

In this case, the tag indicates to the documentation generator that the following function is a constructor.

It has no functional value, nor is it syntactic sugar. It's there in case you decide to generate documentation. Nothing more.

2

My question is does this comment have any functional value or is it just syntactical sugar?

Neither, because it's a comment, not its own syntactical construct.

The comment is simply JSDoc. @Amy's answer has the links for that.

Ingo Bürk
  • 16,020
  • 5
  • 56
  • 88