NG.VII · Angular 22 practice question
When using HttpClient to perform a GET request in Angular, which method is preferred for ensuring the response data is automatically parsed and available as a strongly typed object, compared to using `HttpClient.get()` without explicitly specifying a type?
Check answer and explanation
Correct answer: Providing the expected type as the generic argument to the `HttpClient.get<T>(url)` method.
Explanation
Providing the type argument (e.g., `HttpClient.get<User[]>(url)`) instructs Angular's HttpClient module to deserialize the incoming JSON payload directly into the specified TypeScript type, providing compile-time type safety.
Common trap
Option C is misleading; while Angular often defaults to JSON parsing for modern APIs, explicitly typing is the mechanism to guarantee the correct type handling and avoid runtime errors. Option A defeats the purpose of using strong typing upfront.
Source: HTTP Client documentation (Angular guides) - https://angular.dev/guide/http
Checked against the cited text on 2026-11-27.