-
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Proposal
Add an optional generic type parameter to json() methods on Response and Request for better TypeScript ergonomics.
Current signature
json(): Promise<unknown>;Proposed signature
json<T = unknown>(): Promise<T>;Benefits
- Allows
response.json<MyType>()instead of(await response.json()) as MyType - Default
unknownmaintains current strict behavior - Fully backward compatible - existing code continues to work
- Consistent with other OpenWorkers APIs like
KV.get<T>()andDB.query<T>()
Example
// Current (still works)
const data = (await response.json()) as { text: string };
// Proposed (new option)
const data = await response.json<{ text: string }>();Affected types
Response.json()(line 139 in fetch.d.ts)Request.json()(line 230 in fetch.d.ts)
Metadata
Metadata
Assignees
Labels
No labels