UNPKG

1.16 kBTypeScriptView Raw
1/**
2Returns 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.
3*/
4import { KyResponse } from './response.js';
5export interface ResponsePromise extends Promise<KyResponse> {
6 arrayBuffer: () => Promise<ArrayBuffer>;
7 blob: () => Promise<Blob>;
8 formData: () => Promise<FormData>;
9 /**
10 Get the response body as JSON.
11
12 @example
13 ```
14 import ky from 'ky';
15
16 const json = await ky(…).json();
17 ```
18
19 @example
20 ```
21 import ky from 'ky';
22
23 interface Result {
24 value: number;
25 }
26
27 const result = await ky(…).json<Result>();
28 ```
29 */
30 json: <T = unknown>() => Promise<T>;
31 text: () => Promise<string>;
32}