deno.land / x / ky@v0.31.3 / source / types / ResponsePromise.ts

ResponsePromise.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**Returns a `Response` object with `Body` methods added for convenience. So you can, for example, call `ky.get(input).json()` directly without having to await the `Response` first. When called like that, an appropriate `Accept` header will be set depending on the body method used. Unlike the `Body` methods of `window.Fetch`; these will throw an `HTTPError` if the response status is not in the range of `200...299`. Also, `.json()` will return an empty string if the response status is `204` instead of throwing a parse error due to an empty body.*/import {KyResponse} from './response.js';
export interface ResponsePromise extends Promise<KyResponse> { arrayBuffer: () => Promise<ArrayBuffer>;
blob: () => Promise<Blob>;
formData: () => Promise<FormData>;
// TODO: Use `json<T extends JSONValue>(): Promise<T>;` when it's fixed in TS. // See https://github.com/microsoft/TypeScript/issues/15300 and https://github.com/sindresorhus/ky/pull/80 /** Get the response body as JSON.
@example ``` import ky from 'ky';
const json = await ky(…).json(); ```
@example ``` import ky from 'ky';
interface Result { value: number; }
const result = await ky(…).json<Result>(); ``` */ json: <T = unknown>() => Promise<T>;
text: () => Promise<string>;}
ky

Version Info

Tagged at
a year ago