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:
parent
f2410b4481
commit
1c4028a381
3 changed files with 11 additions and 0 deletions
1
cli/dts/lib.dom.d.ts
vendored
1
cli/dts/lib.dom.d.ts
vendored
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
|
1
ext/fetch/lib.deno_fetch.d.ts
vendored
1
ext/fetch/lib.deno_fetch.d.ts
vendored
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue