Currently working with Angular 7.x.x and TypeScript version 3.2.4.
I have defined two TypeScript interfaces where one extends the other:
Main interface:
export interface Result {
var1: string;
var2: number;
var3: boolean;
}
The second interface adds a property:
export interface ResultPlus extends Result {
var4: boolean;
}
A service is returning Observable<Result[]>
.
In my component, I am subscribing to this service:
dataArray: ResultPlus[] = [];
getResults(): void {
this.service.getResults()
.subscribe(data => {
**this.dataArray** = (data as unknown as ResultPlus);
});
}
(There are no * in the code)
Now this.dataArray (bold above - **) is underlined in red and displays the error message:
error TS2740: Type 'ResultPlus' is missing the following properties from type 'ResultPlus[]': length, pop, push, concat, and 26 more.
What could be causing this issue?
Appreciate any help in advance!