How can I make something like the following work without "Error: cannot append type double to type string[]" ? T[] some_function(T[] var) { T[] var2; double a = 12.34; string b = "hello"; if(typeof(var).stringof == "double") { var2 ~= a; } if(typeof(var).stringof == "string") { var2 ~= b; } ... }