You can specify Person as a type parameter to the get call, but doing so is — in this instance — redundant.

Whether or not specifying a type parameter will effect any compile-time behaviour depends upon the type of the type guard’s parameter. The type guard in the example takes a parameter of type any, so the guard function’s T will be inferred as any. That means the map operator can be applied to Observable<any>, so it doesn’t matter what type parameter is specified for the get call. For example, this would be fine:

const person = http.get<Cat>(`/people/${id}`).map(guard(isPerson));

And person would be inferred to be Observable<Person>.

However, you would need to specify a type parameter to the get call if you had a guard that took a parameter that was, for example, a general interface, from which other more specific interfaces were extended.

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store