-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
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:
regsebcramforce and balazsorban44cramforce, balazsorban44 and zardoy
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
