Reputation: 3772
Given the following Typescript:
class Tester{
constructor(data){
this.Data = data;
}
}
which generates the following Javascript:
var Tester = (function () {
function Tester(data) {
this.Data = data;
}
return Tester;
})();
Are there any reasons why the Typescript is invalid when the resulting Javascript appears to be valid (and works)?
Upvotes: 0
Views: 57
Reputation: 1160
Add your "Data" member to your class :
class Tester {
public Data: string;
constructor(data) {
this.Data = data;
}
}
UPDATE
There is a shorter way to define class members :
class Tester {
constructor(private data: string) {
// this constructor signature defines a private member for the class
// and initializes it upon the constructor being called with a parameter.
}
getData(): string {
return this.data;
}
}
Upvotes: 1