Javascript classes vs typescript classes

  1. /** @class */ is just a comment
  2. TypeScript's default target is ES5 so it transpiles to JS code that can execute on browsers as old as IE11. If you set ES6 as target, you'll notice that JS classes will be used
  3. ES5 way for writing classes is to use a function as a constructor, but the result when executing the code is exactly the same as ES6 classes

I'm answering to complete the third question.

  1. In ECMAScript standard, what is between /* and */ is just a comment, but it's possible that TypeScript transpiler or debugger use this annotations for something more.
  2. As said in the other answers, by default TypeScript transpile for ECMAScript 5 (ES5), for better compatibility with old browsers, and that it's a way to do something like class in ES5.
  3. The ES6 classes are similar to TypeScript classes, but TypeScript also has public/protected/private modifiers, that there aren't in ES6 classes. Also, in TypeScript you will have advantages by the stronger typing, which includes even better autocomplete in some editors (like Visual Studio Code, of course it depends of the editor).

Answering your questions:

  1. @class is a kind of annotation/comment that nothing as to do with the standard.

  2. In ES5 (let's say "classic JavaScript") there are no classes, but there is a way to simulate their behaviour, also when TypeScript code is transpiled to ES5. That way to code "classes" (remember that they aren't there) is a bit harder compared to new specifications.

  3. See answer 2 too. Also:

Since the modern JavaScript ECMAScript 6 specification (ES6), now JavaScript has classes. TypeScript is a kind of evolution of ES6. In ES6, it would be like this:

class User {
  constructor(name, email) {
    this.name = name;
    this.email = email;
  }
}

var newUser = new User('Rohit Bhatia', '[email protected]');