'What's the difference between the 2 model configs in api calls

I have the following method calling an api in my service file:

getDetail(id: number): Observable<any> {
        return this.http.get<any>("api/detail/" + id, { responseType: 'json', observe: 'response' })
    }

I'm being lazy and just using any for now as the model/interface.

My question is what's the difference between the 2 different anys? In what circumstances could they possibly be different from one another? I sometimes see other people leaving off the 2nd any from the second line, ie:

return this.http.get("api/detail/" + id, { responseType: 'json', observe: 'response' })


Solution 1:[1]

My question is what's the difference between the 2 different anys?

none, it just says that any is of type any (duuuh, you don't say)

In what circumstances could they possibly be different from one another?

when you want to make your life even harder and you want to cheat compiler into thinking that return type is of given type

class MyType{public hello(){console.log("hi!")}}

getDetail(id: number): Observable<MyType> {
        //turn off type controll
        return this.http.get<any>("api/detail/" + id, { responseType: 'json', observe: 'response' })
    }

getDetail(5).subscribe(ret=>ret.hello());; //good luck in doing that, but compiler wont complain

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Antoniossss