Hi I’m trying to use constructibles to instantiate a class in a callback. This constructible needs to have certain fields.
Here is an example of what I mean:
import haxe.Constraints;
// This is from an external library (deepnightlibs)
class ExternalClass<T:Recyclable> {
public function new(valueConstructor:Void->T) {}
}
private typedef Recyclable = {
function recycle():Void;
}
class Test {
static function main() {
testFunc(TestClass);
}
@:generic
static function testFunc<T:Constructible<Void->Void>>(cls:Class<T>):T {
// >> It errors here: "testFunc.T should be { recycle : () -> Void }" <<
return new ExternalClass(() -> new T());
}
}
class TestClass {
public function new() {}
public function recycle() {}
}
However there’s an issue, the callback requires that the constructible has certain fields (in this case recycle()
.
Pretty much ExternalClass
requires a callback that returns a T:Recyclable
. How would I do this with constructibles?
Here is the haxe playground of the above code and the error: