Hi I’m trying to make a typedef that has setters in them. I got about this far:
typedef PosSetter = {
var x:Float;
}
function setX(s:PosSetter) {
s.x += 5;
}
class Player {
public var x(default, set):Float = 0;
function set_x(x:Float):Float {
this.x = x;
return x;
}
public function new() {}
}
class Player2 {
public var x:Float; // This works, but I need it to work with setters like for `Player`
public function new() {}
}
class Test {
static function main() {
setX(new Player()); // Errors here
}
}
/*
22 | setX(new Player()); // Errors here
| ^^^^^^^^^^^^
| Player should be PosSetter
| Inconsistent setter for field x : set should be default
| For function argument 's'
*/
Here is the playground link: Try Haxe!
How would I get typedef to accept classes that have setters instead of values like I have for Player
here?