I have the following typings declaration:
public static Loop<Type>(arr:Type[], callback:(obj:Type) => void):void;
This describes the signature for a function implemented with native JavaScript. It loops through each object in an array and passes it to the callback function, e.g.:
Loop(["hello", "world"], function(value)
{
console.log(value);
});
I get working intellisense when used like in the example above, but I also want it working when the array can be of different types, e.g.:
let arr: string[] | number[] = [];
Loop(arr, function(value)
{
console.log(value);
});
But the example above does not work - "value" is described with the 'any' type, rather than "string | number".
However, if the array is declared like let arr: (string|number)[], it works as expected. But I'm not interested in having mixed arrays. It's either a string array or number array.
Can I declare the signature for Loop to work with e.g. string[] | number[] ?
-- Thanks in advance