I have been developing an Angular application and working with two interfaces: IAbc
and IXyz
.
interface IAbc {
id: number,
name: string
}
interface IXyz {
id: number,
value: string | number | Date | IAbc[];
}
In my code, I initialize a variable someVar: IXyz;
with some data.
someVar = {
id: 100,
value: [
{
id: 1,
name: 'abc'
},
{
id: 2,
name: 'xyz'
}
]
};
However, when trying to perform an operation using forEach
on the nested array in value
, I encounter an error:
Property 'forEach' does not exist on type 'string | number | Date | IAbc[]'.
Property 'forEach' does not exist on type 'string'.(2339)
Although logically it should work, I suspect there might be a TypeScript issue. I have created a playground link demonstrating this issue.
I appreciate any insights or suggestions. Thank you!
P.S.: While using any
could resolve this, it has been restricted by the linting rules of the application.