I am new to TypeScript and JavaScript classes!
I was learning TypeScript where I created something as simple as this
class User {
name: string;
email: string;
constructor(name: string, email: string) {
this.name = name;
this.email = email;
}
}
let newUser = new User("Rohit Bhatia", "[email protected]");
and this was given to me as equivalence
var User = /** @class */ (function () {
function User(name, email) {
this.name = name;
this.email = email;
}
return User;
}());
var newUser = new User("Rohit Bhatia", "[email protected]");
Now, I have three questions
what is
@class(or@in general in JavaScript)?var User = /** @class */ (function () {classes are in JavaScript as well? So why doesn't TypeScript transform them into JS classes?
in TS class we can do something like this
class User { name: string; email: string;
but can't we do something like this in JavaScript? Or what is the difference between JS classes and TS classes?
targetoption, I believe the class will be output as a proper JS class.