3.3.1 Construction of generic type parameters

A type parameter is said to be generic if its containing class or method is generic.

It is not possible to construct normal type parameters, e.g. new T() is a compiler error. The reason for this is that Haxe generates only a single function and the construct makes no sense in that case. This is different when the type parameter is generic: Since we know that the compiler will generate a distinct function for each type parameter combination, it is possible to replace the Tnew T() with the real type.

It should be noted that top-down inference is used here to determine the actual type of T. There are two requirements for this kind of type parameter construction to work: The constructed type parameter must be

Here, 1. is given by make having the @:generic metadata, and 2. by T being constrained to Constructible. The constraint holds for both String and haxe.Template as both have a constructor accepting a singular String argument. Sure enough, the relevant JavaScript output looks as expected: