Skip to content

Commit

Permalink
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 22 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -81,9 +81,30 @@ export interface Options extends RequestInit {
*/
export interface ResponsePromise extends Promise<Response> {
arrayBuffer(): Promise<ArrayBuffer>;

blob(): Promise<Blob>;

formData(): Promise<FormData>;
json(): Promise<JSONValue>;

// TODO: Use `json<T extends JSONValue>(): Promise<T>;` when it's fixed in TS.
// See https://github.com/sindresorhus/ky/pull/80
/**
* Get the response body as JSON.
*
* @example
*
* const json = await ky(…).json();
*
* @example
*
* interface Result {
* value: number;
* }
* const result = await ky(…).json<Result>();
*/
json<T = JSONValue>(): Promise<T>;

text(): Promise<string>;
}

5 changes: 5 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -68,3 +68,8 @@ ky.post(server.url, {
});

expectType<JSONValue>(await ky(server.url).json());

interface Result {
value: number;
}
expectType<Result>(await ky(server.url).json<Result>());

0 comments on commit ce12902

Please sign in to comment.