retry.ts
This file
Path
test-d/retry.ts
42 lines · 1.3 KiB · TypeScript
Last changed by
Support readonly inputs and explicit undefined in TypeScript optionsSindre Sorhusbefore adoption51b3177
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243import {expectTypeOf} from 'expect-type';import type {InitHook, RetryOptions} from 'ky';
const retryOptions: RetryOptions = { methods: ['get'] as const, statusCodes: [503] as const, afterStatusCodes: [503] as const,};
const methods = ['get'] as const;const statusCodes = [503] as const;const afterStatusCodes = [503] as const;const readonlyRetryOptions: RetryOptions = {methods, statusCodes, afterStatusCodes};
expectTypeOf(readonlyRetryOptions).toEqualTypeOf(retryOptions);
const initHook: InitHook = options => { if (typeof options.retry === 'object') { options.retry.methods?.push('post'); options.retry.statusCodes?.push(500); options.retry.afterStatusCodes?.push(503); options.retry.methods = undefined; options.retry.statusCodes = undefined; options.retry.afterStatusCodes = undefined; }};
expectTypeOf(initHook).toEqualTypeOf<InitHook>();
const defaultRetryDelay: RetryOptions = {delay: undefined};expectTypeOf(defaultRetryDelay.delay).toMatchTypeOf<RetryOptions['delay']>();
const resetRetryOptions: RetryOptions[] = [ {limit: undefined}, {methods: undefined}, {statusCodes: undefined}, {afterStatusCodes: undefined}, {maxRetryAfter: undefined}, {backoffLimit: undefined}, {retryOnTimeout: undefined},];expectTypeOf(resetRetryOptions).toEqualTypeOf<RetryOptions[]>();