Nothing in the code says what type this value has, typically an empty list [] or map {}
that is never used in a way that fixes its element type. Add a type annotation.
Wrong#
fn main() {
let xs = []
print(xs.len())
}Fixed#
fn main() {
let xs: [int] = []
print(xs.len())
}Common causes#
- An empty collection literal with no annotation.
nonewith nothing that says what it's missing.- Type arguments are never written at call sites: annotate the variable instead
(
let ts: [Todo] = json.decode(s)?).