Generic types for flexibility
Why it matters
An API that returns Promise<any> for network requests or data operations forces every TypeScript consumer to cast results manually — const users = await client.get('/users') as User[]. This eliminates compile-time type checking at exactly the boundary where runtime errors are most common. ISO 25010 modifiability suffers because any change to the response shape goes undetected until runtime. The consumer cannot trust the type system to catch contract mismatches between their models and your API's actual output.
Severity rationale
Low because the impact is limited to TypeScript consumers and does not cause runtime failures — the type ergonomics are poor but the functionality remains intact.
Remediation
Add generic type parameters to data-handling methods so consumers can specify their expected response types.
// Before — returns any:
export class Client {
async request(path: string): Promise<any> { /* ... */ }
}
// After — generic return type:
export class Client {
async request<T>(path: string): Promise<T> { /* ... */ }
}
// Consumer gets full type safety:
const users = await client.request<User[]>('/api/users')
// ^? User[]
For event emitters, use a typed event map: on<K extends keyof Events>(event: K, handler: (data: Events[K]) => void). At least 50% of data-handling APIs should use generics before this check passes.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the SDK / Package Quality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · maintainability.modifiability — Modifiability — generics allow API evolution without breaking consumers
- iso-25010:2011 · compatibility.interoperability — Interoperability — typed generics integrate with consumer TypeScript toolchains
Taxons
History
- 2026-04-18·v1.0.0·Initial import from sdk-package-quality·automated