1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix: add types for Response.json (#14655)

This commit is contained in:
Luca Casonato 2022-05-18 16:16:11 +02:00 committed by GitHub
parent f2410b4481
commit 1c4028a381
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -11275,6 +11275,7 @@ interface Response extends Body {
declare var Response: { declare var Response: {
prototype: Response; prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response; new(body?: BodyInit | null, init?: ResponseInit): Response;
json(data: unknown, init?: ResponseInit): Response;
error(): Response; error(): Response;
redirect(url: string | URL, status?: number): Response; redirect(url: string | URL, status?: number): Response;
}; };

View file

@ -1533,3 +1533,12 @@ Deno.test(
assertEquals(length, 'Some("4")'); assertEquals(length, 'Some("4")');
}, },
); );
Deno.test(async function staticResponseJson() {
const data = { hello: "world" };
const resp = Response.json(data);
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "application/json");
const res = await resp.json();
assertEquals(res, data);
});

View file

@ -383,6 +383,7 @@ type ResponseType =
/** This Fetch API interface represents the response to a request. */ /** This Fetch API interface represents the response to a request. */
declare class Response implements Body { declare class Response implements Body {
constructor(body?: BodyInit | null, init?: ResponseInit); constructor(body?: BodyInit | null, init?: ResponseInit);
static json(data: unknown, init?: ResponseInit): Response;
static error(): Response; static error(): Response;
static redirect(url: string, status?: number): Response; static redirect(url: string, status?: number): Response;