4 ms·
I'm not sure I understand the use case for this, but I had a go in the playground let a = [3] a = [''] // this works? a[0].length // but this fails?
by dalmo3 4y ago
I'm not sure I understand the use case for this, but I had a go in the playground
let a = [3]
a = [''] // this works?
a[0].length // but this fails?
Error message is
> expecting possible candidates all failed: candidate array failed: expecting number but got string. candidate object failed: missing field 'length' but got number.
- jiangmy 4y agoGood One! There are two issues here: 1. Tuple or Array? The inferred type will be different depending on that decision. Currently, I go for the Array one, so if you remove the `a[0].length` line, you will see `a` be inferred as `[string|number]`. But this will change if I think about this more thoroughly. What are your thoughts? 2. const/let constrain, constexpr, `if guarding,` and some internal methods are not implemented yet, so this is a false negative. But indeed will do!