Import it from ky.
tstype ResponsePromise<T = unknown> = {
arrayBuffer: () => Promise<ArrayBuffer>;
blob: () => Promise<Blob>;
formData: () => Promise<FormData>;
bytes: () => Promise<Uint8Array<ArrayBuffer>>;
json: {
<JsonType = T>(schema?: undefined): Promise<JsonType>;
<Schema extends StandardSchemaV1>(schema: Schema): Promise<StandardSchemaV1InferOutput<Schema>>;
};
text: () => Promise<string>;
} & Promise<KyResponse<T>>;
Properties
| Name | Type | Default | Description |
|---|---|---|---|
arrayBuffer | () => Promise<ArrayBuffer> | ||
blob | () => Promise<Blob> | ||
formData | () => Promise<FormData> | ||
bytes | () => Promise<Uint8Array<ArrayBuffer>> | Get the response body as raw bytes. | |
json | { /** 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 result1 = await ky(…).json<Result>(); // or const result2 = await ky<Result>(…).json(); ``` */ <JsonType = T>(schema?: undefined): Promise<JsonType>; /** Get the response body as JSON and validate it with a Standard Schema. Use a Standard Schema compatible validator (for example, Zod 3.24+). Throws a SchemaValidationError when validation fails. @example ``` import ky from 'ky'; import {z} from 'zod'; const userSchema = z.object({name: z.string()}); const user = await ky('/api/user').json(userSchema); ``` */ <Schema extends StandardSchemaV1>(schema: Schema): Promise<StandardSchemaV1InferOutput<Schema>>; } | ||
text | () => Promise<string> |
Members
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>— Attaches callbacks for the resolution and/or rejection of the Promise.catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>— Attaches a callback for only the rejection of the Promise.
Was this page helpful?