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
This will work:
class Foo {}
class Bar {}
var f: any[][] = [
[Foo, [1, 2, 3]],
[Bar, [7, 8, 9]],
];
This says you have a two-dimensional array whose values can be anything (Foo, Bar, other arrays, etc). You could also use a type assertion for your nested arrays:
class Foo {}
class Bar {}
var f = [
[<any>Foo, [1, 2, 3]],
[<any>Bar, [7, 8, 9]],
];
The presence of a single any in the inner array forces the compiler to infer its type as any[].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With