This is as far as I was able to reduce the problem to:
interface Word {
value: string | string[];
}
const w: Word = {
value: [] as string[]
// also tried:
// value: []
// value: ['test']
}
w.value.push('')
The last line errors in my IDE because "push" does not exist for the type "string | string[]" (ts2339). It also wouldn't compile!
Is it a bug? Is it feature? How to help this?
string[]to avoid things like this.was being of typeWord, the compiler giveswthat type. Even though you initializew.valuetostring[], the compiler does not narrowwto{value: string[]}upon assignment. See ms/TS#33205. Personally I'd just not annotatewat all and let the compiler infer it as{value: string[]}to begin with.