TypeScript: can't write heterogeneous array literals
typescript
Solution
It looks like typescript does have heterogeneous arrays now. So, since this question came up first when I looked for this, and since it's hard to find it otherwise, here how this code can be written now:
class Foo {}
class Bar {}
var f: [Foo|Bar, number[]][] =
[[new Foo(), [1, 2, 3]],
[new Bar(), [7, 8, 9]]];
(Now if this goes down the road of type syntax mimicking expressions, the type would also get a syntax of `[Foo|Bar, [...number]][]`...)
It even works with function arguments, so this typechecks fine:
function foo([obj,nums]: [Foo|Bar, number[]]) {
for (let i of nums) console.log(`i = ${i}`);
}
f.forEach(foo);
and the extreme version:
f.forEach(([obj,nums]: [Foo|Bar, number[]]) => {
for (let i of nums) console.log(`i = ${i}`); });
Problem
what type asserts do i need to get this to compile? ``` class Foo {} class Bar {} var f = [ [Foo, [1, 2, 3]], [Bar, [7, 8, 9]], ]; ``` error: ``` Incompatible types in array literal expression ```