Do you know the solution to realize something like the following example :
import haxe.ds.Vector
typedef Toto = List<Vector>
to be able to do then a function like
function mafonction( unparam:Toto) { …
Do you know the solution to realize something like the following example :
import haxe.ds.Vector
typedef Toto = List<Vector>
to be able to do then a function like
function mafonction( unparam:Toto) { …
Vector<T>
needs a type, so you should write:
// Toto.hx
import haxe.ds.Vector;
typedef Toto<T> = List<Vector<T>>;
// usage
var t:Toto<Foo>;
If you want a generic “untyped” Toto you can defined the type as:
// Toto.hx
import haxe.ds.Vector;
typedef Toto = TotoOf<Dynamic>
typedef TotoOf<T> = List<Vector<T>>;
// usage
var t2:TotoOf<Foo>;
var t:Toto = t2;
Normally Toto
as TotoOf<Dynamic>
should unify with any TotoOf<T>
.
By using Toto<T>
like @elsassph said, you can also add a type parameter to your function like this: Try Haxe !
static function myFunction<T>(param:Toto<T>)
See the manual on type parameters: Type Parameters (Type System) - Haxe - The Cross-platform Toolkit
De rien mec.
De même #100%FrenchThread
© 2018-2020 Haxe Foundation - Powered by Discourse