diff --git a/source/create.ts b/source/create.ts index f77113e5c..3d822da16 100644 --- a/source/create.ts +++ b/source/create.ts @@ -46,25 +46,11 @@ const errors = { const {normalizeArguments} = PromisableRequest; -export type HTTPAlias = - | 'get' - | 'post' - | 'put' - | 'patch' - | 'head' - | 'delete'; - export type GotReturn = Request | CancelableRequest; - -interface GotStreamFunction { - (url: string | URL, options?: Options & {isStream?: true}): Request; - (options?: Options & {isStream?: true}): Request; -} +export type HandlerFunction = (options: NormalizedOptions, next: (options: NormalizedOptions) => T) => T | Promise; const getPromiseOrStream = (options: NormalizedOptions): GotReturn => options.isStream ? new Request(options.url, options) : asPromise(options); -export type HandlerFunction = (options: NormalizedOptions, next: (options: NormalizedOptions) => T) => T | Promise; - export interface ExtendOptions extends Options { handlers?: HandlerFunction[]; mutableDefaults?: boolean; @@ -79,7 +65,7 @@ type Except = Pick; +export type StrictOptions = Except; type ResponseBodyOnly = {resolveBodyOnly: true}; export interface GotPaginate { @@ -124,6 +110,28 @@ export interface GotRequest { (options: Options): CancelableRequest | Request; } +export type HTTPAlias = + | 'get' + | 'post' + | 'put' + | 'patch' + | 'head' + | 'delete'; + +const aliases: readonly HTTPAlias[] = [ + 'get', + 'post', + 'put', + 'patch', + 'head', + 'delete' +]; + +interface GotStreamFunction { + (url: string | URL, options?: Options & {isStream?: true}): Request; + (options?: Options & {isStream?: true}): Request; +} + export type GotStream = GotStreamFunction & Record; export interface Got extends Record, GotRequest { @@ -144,15 +152,6 @@ export interface Got extends Record, GotRequest { mergeOptions(...sources: Options[]): NormalizedOptions; } -const aliases: readonly HTTPAlias[] = [ - 'get', - 'post', - 'put', - 'patch', - 'head', - 'delete' -]; - export const defaultHandler: HandlerFunction = (options, next) => next(options); export const mergeOptions = (...sources: Options[]): NormalizedOptions => { diff --git a/test/arguments.ts b/test/arguments.ts index 1f9dadf17..4e64c65fa 100644 --- a/test/arguments.ts +++ b/test/arguments.ts @@ -3,7 +3,7 @@ import {parse, URL, URLSearchParams} from 'url'; import test from 'ava'; import {Handler} from 'express'; import pEvent = require('p-event'); -import got from '../source'; +import got, {StrictOptions} from '../source'; import withServer from './helpers/with-server'; const echoUrl: Handler = (request, response) => { @@ -409,3 +409,13 @@ test('fallbacks to native http if `request(...)` returns undefined', withServer, t.is(body, '/'); }); + +test('strict options', withServer, async (t, server, got) => { + server.get('/', echoUrl); + + const options: StrictOptions = {}; + + const {body} = await got(options); + + t.is(body, '/'); +});