Type 'Post[]' is not assignable to type 'Observable<Post[]>': error TS2322

2490 views angular

I have googled both the message and error and it seems the issue I keep finding is not what I am dealing with.

I am an angular noob and feel I am finally close to getting my service wired up.

I am getting the above error on my component

it will squawk at the this.posts below.

 getPosts() {
  .subscribe((data: Post[]) => this.posts = data);};

and my service in case theres an issue there.

public get(): Observable<Post[]> {
return this.http

Someone save my morning please!

answered question

What type is this.posts? I'm guessing Observable<Post[]>?

Make sure this.posts is not Observable<Post[]> that might be your issue

1 Answer


just return the http.

return this.http

Declare the type of posts as post[]

posts: Post[];

posted this

Have an answer?


Please login first before posting an answer.