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
Preserve JSON types when cloning requests and responsesSindre Sorhusbefore adoptionf4886ca
lines 1–12why, one step back1import {expectTypeOf} from 'expect-type';2import ky from 'ky';34const response = await ky<{name: string}>('https://example.com');5const clone = response.clone();67expectTypeOf(clone.json()).toEqualTypeOf<Promise<{name: string}>>();8expectTypeOf(clone.clone().json()).toEqualTypeOf<Promise<{name: string}>>();9expectTypeOf(clone.json<{id: number}>()).toEqualTypeOf<Promise<{id: number}>>();1011const unknownResponse = await ky('https://example.com');12expectTypeOf(unknownResponse.clone().json()).toEqualTypeOf<Promise<unknown>>();