Skip to content
Myr

Add typed JSON response (#437)

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

authored by Dominik · committed by GitHub · parent f34fb1f · Browse files · 7 files+51 added−40 removed
This commit

State

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

Diff stats

7 files+51 added−40 removed

  • tests:+5 added−1 removed
  • other:+46 added−39 removed

7 files+51 added−40 removed

modified:source/core/Ky.ts+1 added-1 removed
1import {HTTPError} from '../errors/HTTPError.js';2import {TimeoutError} from '../errors/TimeoutError.js';3import type {Hooks} from '../types/hooks.js';4import type {Input, InternalOptions, NormalizedOptions, Options, SearchParamsInit} from '../types/options.js';5import {ResponsePromise} from '../types/response.js';5import {ResponsePromise} from '../types/ResponsePromise.js';6import {deepMerge, mergeHeaders} from '../utils/merge.js';7import {normalizeRequestMethod, normalizeRetryOptions} from '../utils/normalize.js';8import {delay, timeout, TimeoutOptions} from '../utils/time.js';9import {ObjectEntries} from '../utils/types.js';
315 unmodified lines
modified:source/types/ky.ts+1 added-1 removed
modified:source/types/response.ts+1 added-35 removed
added:source/types/ResponsePromise.ts+39 added
modified:source/index.ts+2 added-1 removed
42 unmodified lines
43 BeforeErrorHook,44 AfterResponseHook,45} from './types/hooks.js';4647export {ResponsePromise} from './types/response.js';47export {ResponsePromise} from './types/ResponsePromise.js';48export {KyResponse} from './types/response.js';49export {HTTPError} from './errors/HTTPError.js';50export {TimeoutError} from './errors/TimeoutError.js';
modified:test/main.ts+5 added-1 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import delay from 'delay';4import {expectTypeOf} from 'expect-type';5import ky, {TimeoutError} from '../source/index.js';6import {createHttpTestServer} from './helpers/create-http-test-server.js';7import {parseRawBody} from './helpers/parse-body.js';8
653 unmodified lines
662 ...JSON.parse(text),663 extra: 'extraValue',664 }),665 });665 const responseJson = await response.json();666667 const responseJson = await response.json<{hello: string; extra: string}>();668669 expectTypeOf(responseJson).toMatchTypeOf({hello: 'world', extra: 'extraValue'});670671 t.deepEqual(responseJson, {672 ...json,673 extra: 'extraValue',674 });
28 unmodified lines
modified:package.json+2 added-1 removed
69 unmodified lines
70 "playwright-chromium": "^1.19.2",71 "raw-body": "^2.5.1",72 "ts-node": "^10.6.0",73 "typescript": "~4.6.2",74 "xo": "^0.48.0"74 "xo": "^0.48.0",75 "expect-type": "^0.13.0"76 },77 "sideEffects": false,78 "xo": {79 "envs": [
40 unmodified lines