response-clone.ts
This file
Path
test-d/response-clone.ts
12 lines · 528 bytes · TypeScript
Last changed by
Preserve JSON types when cloning requests and responsesSindre Sorhusbefore adoptionf4886ca
History of this fileTake it
12345678910111213import {expectTypeOf} from 'expect-type';import ky from 'ky';
const response = await ky<{name: string}>('https://example.com');const clone = response.clone();
expectTypeOf(clone.json()).toEqualTypeOf<Promise<{name: string}>>();expectTypeOf(clone.clone().json()).toEqualTypeOf<Promise<{name: string}>>();expectTypeOf(clone.json<{id: number}>()).toEqualTypeOf<Promise<{id: number}>>();
const unknownResponse = await ky('https://example.com');expectTypeOf(unknownResponse.clone().json()).toEqualTypeOf<Promise<unknown>>();