Skip to content

Commit

Permalink
Make options.responseType optional when using a template
Browse files Browse the repository at this point in the history
Fixes #1178
  • Loading branch information
szmarczak committed May 3, 2020
1 parent 50ef99a commit 9ed0a39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface ExtendOptions extends Options {
}

export type OptionsOfTextResponseBody = Merge<Options, {isStream?: false; resolveBodyOnly?: false; responseType?: 'text'}>;
export type OptionsOfJSONResponseBody = Merge<Options, {isStream?: false; resolveBodyOnly?: false; responseType: 'json'}>;
export type OptionsOfJSONResponseBody = Merge<Options, {isStream?: false; resolveBodyOnly?: false; responseType?: 'json'}>;
export type OptionsOfBufferResponseBody = Merge<Options, {isStream?: false; resolveBodyOnly?: false; responseType: 'buffer'}>;
export type StrictOptions = Except<Options, 'isStream' | 'responseType' | 'resolveBodyOnly'>;
export type StreamOptions = Merge<Options, {isStream?: true}>;
Expand Down
14 changes: 14 additions & 0 deletions test/response-parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'ava';
import {Handler} from 'express';
import getStream = require('get-stream');
import {HTTPError, ParseError} from '../source';
import withServer from './helpers/with-server';

Expand Down Expand Up @@ -222,3 +223,16 @@ test('shortcuts result properly when retrying in afterResponse', withServer, asy
t.is(text, proper);
t.is(buffer.compare(Buffer.from(proper)), 0);
});

test('responseType is optional when using template', withServer, async (t, server, got) => {
const data = {hello: 'world'};

server.post('/', async (request, response) => {
response.end(await getStream(request));
});

const jsonClient = got.extend({responseType: 'json'});
const {body} = await jsonClient.post<typeof data>('', {json: data});

t.deepEqual(body, data);
});

0 comments on commit 9ed0a39

Please sign in to comment.