PR REVIEWTypeScript `any` Leaking through Generics#310MicrosoftLinear
00:00Mid~10 min
PULL REQUEST
Open#310 · 1 commit
TypeScript `any` Leaking through Generics
mid-dev-44 wants to mergechore/api-client-wrappermain
MI
mid-dev-44
1 file changed · 2 hours ago
YOUR MISSION
A developer created a nice reusable `apiFetch` wrapper. It looks type-safe, but teammates report that if they forget to pass a type parameter, TypeScript silently defaults to `any`, completely disabling type checking for the API response.
Mid~10 min
HINTS (0/3 used)
REVIEWING AS
SR
Senior Engineer
@ Microsoft · Backend Platform
src / utils / api.ts+2 2
1
1
/**
2
2
* A typed wrapper around fetch
3
3
*/
4
export async function apiFetch(url: string) {
+
4
+
export async function apiFetch<T = any>(url: string): Promise<T> {
+
5
5
const response = await fetch(url, {
6
6
headers: { Authorization: `Bearer ${getToken()}` }
7
7
});
8
8
9
return response.json();
+
9
+
return response.json() as Promise<T>;
+
10
10
}
Click any changed line (+/−) to flag an issue · or Approve if everything looks safe