request-options.ts
This file
Path
test-d/request-options.ts
34 lines · 833 bytes · TypeScript
Last changed by
Support readonly inputs and explicit undefined in TypeScript optionsSindre Sorhusbefore adoption51b3177
History of this fileTake it
Support readonly inputs and explicit undefined in TypeScript optionsSindre Sorhusbefore adoption51b3177
lines 1–34why, one step back1import ky, {type Options} from 'ky';23const resetOptions: Options[] = [4 {body: undefined},5 {cache: undefined},6 {credentials: undefined},7 {integrity: undefined},8 {keepalive: undefined},9 {mode: undefined},10 {redirect: undefined},11 {referrer: undefined},12 {referrerPolicy: undefined},13];1415for (const options of resetOptions) {16 void ky('https://example.com', options);17 void ky.create().extend(options);18}1920void ky('https://example.com', {21 hooks: {22 init: [options => {23 options.body = undefined;24 options.credentials = undefined;25 options.cache = undefined;26 }],27 },28});2930// @ts-expect-error - Allowing resets must not accept invalid credentials.31void ky('https://example.com', {credentials: 'invalid'});3233// @ts-expect-error - Allowing resets must not accept invalid bodies.34void ky('https://example.com', {body: 42});