-
Notifications
You must be signed in to change notification settings - Fork 26
No support for field annotations #7
Comments
Seeing the same. In fact, anything with class MyClass {
constructor(xArg:number, yArg:number) {
this.x = xArg;
this.y = yArg;
}
}
var myClass = new MyClass(1, 2);
console.log(myClass);
var myClass2 = new MyClass("test", "test"); // this will fail in the console (as expected) But this doesn't: class MyClass {
x:number;
y:number;
} |
I solved the problem on my side by adding this to the config.json : "memberVariables":true |
Interesting. I can get it to compile by doing that also. I can also define a class like above with: export class Point {
x:int;
} But if I try to instantiate it like so: var point = new Point(5);
console.log(point); I see this in my console:
And this is my config:
|
You get this error because you forgot to write a constructor : export class Point {
x:int;
constructor(x:int){
this.x = x;
}
} |
Shouldn't the transpiler auto-generate the constructor for me? Take a look at the AtScript primer by @mhevery Look at the Field Annotations section, specifically this line: By specifying the fields in this way, the transpiler can generate the constructor which then pre-creates the fields. |
Add a missing option to the traceur compiler in order to play with all atScript functionalities.
It specifies that the transpiler can generate the constructor. But it does not say if the constructor will assign values. In the example provided by @mhevery field variables are assigned to null. class MyClass {
constructor() {
this.x = null; // auto-generated
this.y = null; // auto-generated
}
} But when I transpile the code into es6 using traceur, there is no constructor : class Point {
get x() {
return this.$__0;
}
set x(value) {
this.$__0 = value;
}
get y() {
return this.$__1;
}
set y(value) {
this.$__1 = value;
}
}
Object.defineProperty(Object.getOwnPropertyDescriptor(Point.prototype, "x").set, "parameters", {get: function() {
return [[int]];
}});
Object.defineProperty(Object.getOwnPropertyDescriptor(Point.prototype, "y").set, "parameters", {get: function() {
return [[int]];
}}); So, I agree with you on the fact it does not generate constructor, but anyway according to this document atScript will not auto-assign your fields. So, you'll have to write a constructor. |
work in progress. On Thu Nov 20 2014 at 1:39:03 PM Martin Le Bas [email protected]
|
Tried very simple example:
And it doesn't seem to work. Throws:
The text was updated successfully, but these errors were encountered: