Skip to content
Myr

Type-check `onDownloadProgress` before the request is sent

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sindre Sorhus · committed by Sindre Sorhus · parent d4ce7b1 · Browse files · 2 files+30 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+30 added−5 removed

  • tests:+29 added−0 removed
  • other:+1 added−5 removed

2 files+30 added−5 removed

modified:source/core/Ky.ts+1 added-5 removed
99 unmodified lines
100101// These callbacks are called directly, so a non-function value otherwise surfaces as a runtime error naming Ky's102// own internals rather than the option the caller set.103const validateCallbackOptions = (options: Record<string, unknown>): void => {104 for (const key of ['parseJson', 'stringifyJson', 'fetch'] as const) {104 for (const key of ['parseJson', 'stringifyJson', 'fetch', 'onDownloadProgress'] as const) {105 if (options[key] !== undefined && typeof options[key] !== 'function') {106 throw new TypeError(`The \`${key}\` option must be a function`);107 }108 }
252 unmodified lines
361 ky.#decorateResponse(response);362363 // If `onDownloadProgress` is passed, it uses the stream API internally364 if (ky.#options.onDownloadProgress) {365 if (typeof ky.#options.onDownloadProgress !== 'function') {366 throw new TypeError('The `onDownloadProgress` option must be a function');367 }368365 if (!supportsResponseStreams) {366 throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');367 }368
1188 unmodified lines
modified:test/validation.ts+29 added