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.