I'm a novice when it comes to TypeScript and JavaScript classes!
While learning TypeScript, I created a simple code snippet like this:
class User {
name: string;
email: string;
constructor(name: string, email: string) {
this.name = name;
this.email = email;
}
}
let newUser = new User("Rohit Bhatia", "example@email.com");
and then I was presented with this equivalent code:
var User = /** @class */ (function () {
function User(name, email) {
this.name = name;
this.email = email;
}
return User;
}());
var newUser = new User("Rohit Bhatia", "example@email.com");
Now, I have a few questions:
what does
@class
(or@
in general in JavaScript) mean?var User = /** @class */ (function () {
are classes present in JavaScript as well? If so, why doesn't TypeScript transpile them into JavaScript classes?
In TypeScript classes, we can define properties like this:
class User { name: string; email: string;
But can we do the same thing in plain JavaScript? Is there a difference between JavaScript classes and TypeScript classes?