Closed
Description
Suggestion
🔍 Search Terms
response, responses, static method, json, Response.json()
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
Now that multiple JavaScript runtimes (Chromium, Node.js v18 LTS, Bun, etc) have implemented it, it would be great to get types for the Response.json()
static method (Chrome Platform Status, Mozilla Bugzilla, Response.json()
section in Fetch spec).
Since Response
objects are more commonly used on the backend, maybe backend runtimes can be considered as valid signals that this is ready for inclusion in TypeScript.
📃 Motivating Example
Response.json({abc: 123}, {status: 400});
💻 Use Cases
A shortcut for the following code (more verbose / error prone):
new Response(JSON.stringify({ abc: 123 }), {
status: 400,
headers: {
'Content-Type': 'application/json',
},
});
👀 See also
This has a companion issue + PR in the microsoft/TypeScript-DOM-lib-generator
repo over here: