Performance: Generics in Angular services
LOW IMPACT
Using generics in Angular services mainly affects bundle size and type safety without directly impacting rendering speed or layout performance.
export class DataService<T> { fetchData(url: string): Observable<T> { return this.http.get<T>(url); } }
export class DataService { fetchData(url: string): Observable<any> { return this.http.get(url); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Service using 'any' type | 0 | 0 | 0 | [OK] Good for runtime but poor for maintainability |
| Service using generics with type parameter | 0 | 0 | 0 | [OK] Best for type safety and no runtime cost |