I do not understand the error in the following Minimal Reproducible Example
interface Animal {
properties: Array<{ foo: number }>
}
type Cat = Animal & {
properties: Array<{ foo: number, bar: number }>
}
let cat : Cat = {} as any
cat.properties[0].bar
cat.properties.forEach(prop => prop.bar)
// ^^^^^^^^
// Property 'bar' does not exist on type '{ foo: number; }'.
I expect the two last lines to either fail or succeed the type checking.
Why does cat.properties[0].bar
pass the type checking, while the last line doesn't? Do I really need a cast to make the last line work?
I'd like to merely add some properties to the Animal
interface and its children.