How to define a typedef with List<Vector>?

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>.

1 Like

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

2 Likes

@kLabz and @elsassph thank you for the speed and quality of your answers ! :slight_smile:

De rien mec.

1 Like

De même :slight_smile: #100%FrenchThread

1 Like