I have this problem. I have an interface called Person which has a optional key called asked. I need to pass an array of that interface to a function which return an observable of type Person[] using RXJS.
interface Person {
name string;
asked?: boolean;
}
const persons: Person[] = [
{name: "Wako"},
{name: "Yako"},
{name: "Dot"},
];
const persons$ = (persons: Person[]): Observable<Person[]> {
return of(persons).pipe(
map((p: Person) => {
p.asked = true;
return p;
})
);
}
But I have this problem:
Type 'Observable<Person>' is not assignable to type 'Observable<Person[]>'.
Type 'Person' is missing the following properties from type 'Person[]': length, pop, push, concat, and 16 more.ts(2322)
What does my function persons$ has to do to return a Observable<Person[]>.
map((people) => people.map((person) => ({ ...person, asked: true }))).mapis from RxJS,Array#mapis not.