I have an interface like this. And I am wondering what is the best case to handle this case:
interface Ia {
a: string
}
let a: Ia | Ia[]
console.log(a[0].a)
TS throws me an error:
Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Ia'.
Property '0' does not exist on type 'Ia'.
I know I could use console.log((a as Ia[])[0].a) but it is not readable at all. Does anyone have better suggestions?
Also, the real use case type has many properties inside not the single one a: sting as in the example.
ais an array, why then you say it isIa | Ia[]?as