Bugfix: How to fix HttpClient params type inference for optional que...
Documentation for Sessions
🐛 Bugfix: How to fix HttpClient params type inference for optional que...
Date: 2026-02-17
Time: 14:43:54 UTC
Session: gspace1-111.3
Agent: angular
Confidence: 100%
Status: ✅ Documented
📋 Decision Context
Question:
How to fix HttpClient params type inference for optional query params in listChannels?
Task: Not specified
🎯 Decision Made
Chosen:
Use HttpParams instead of Record for optional params. When userId is undefined, pass new HttpParams(); when defined, use new HttpParams().set('userId', userId). This avoids TypeScript inferring { userId?: undefined } which fails HttpParams/Record index signature.
Options Considered:
- No alternatives documented
💭 Reasoning
Angular HttpClient.get options.params expects HttpParams | Record<string, string|number|boolean|...>. The expression userId ? { userId } : {} yields union type { userId: string } | {}; TypeScript narrows {} to { userId?: undefined }, causing "undefined is not assignable to string|number|boolean" in the index signature. HttpParams is the type-safe, established pattern (see agent-api.service, mcp-data.service).
📁 Files Involved
libs/libs-ai/vitto-hub/src/lib/services/vitto-api.service.ts
🔗 Related
- Decision ID:
dev_1771339434527_jxz6691 - Session: 111
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation