response-size.ts
This file
Path
test-d/response-size.ts
22 lines · 855 bytes · TypeScript
Last changed by
Add `maxResponseSize` optionSindre Sorhusbefore adoption0d59458
History of this fileTake it
Add `maxResponseSize` optionSindre Sorhusbefore adoption0d59458
lines 1–22why, one step back1import {expectTypeOf} from 'expect-type';2import ky, {3 type Options, type KyRequest, type KyError, ResponseSizeError, isResponseSizeError,4} from 'ky';56const options: Options = {maxResponseSize: 1024};7expectTypeOf(options.maxResponseSize).toEqualTypeOf<number | undefined>();89const error = new ResponseSizeError(new Request('https://example.com'), 1024);10expectTypeOf(error).toExtend<KyError>();11expectTypeOf(error.request).toEqualTypeOf<KyRequest>();12expectTypeOf(error.maxResponseSize).toEqualTypeOf<number>();1314const unknownError: unknown = error;15if (isResponseSizeError(unknownError)) {16 expectTypeOf(unknownError).toEqualTypeOf<ResponseSizeError>();17}1819void ky('https://example.com', {maxResponseSize: Number.POSITIVE_INFINITY});2021// @ts-expect-error - The size limit must be a number.22void ky('https://example.com', {maxResponseSize: '1024'});