1
1
import process from 'node:process' ;
2
- import { Buffer } from 'node:buffer' ;
2
+ import type { Buffer } from 'node:buffer' ;
3
3
import { promisify , inspect } from 'node:util' ;
4
4
import { URL , URLSearchParams } from 'node:url' ;
5
5
import { checkServerIdentity } from 'node:tls' ;
@@ -21,7 +21,7 @@ import type {InspectOptions} from 'node:util';
21
21
import is , { assert } from '@sindresorhus/is' ;
22
22
import lowercaseKeys from 'lowercase-keys' ;
23
23
import CacheableLookup from 'cacheable-lookup' ;
24
- import http2wrapper , { ClientHttp2Session } from 'http2-wrapper' ;
24
+ import http2wrapper , { type ClientHttp2Session } from 'http2-wrapper' ;
25
25
import { isFormData } from 'form-data-encoder' ;
26
26
import type { FormDataLike } from 'form-data-encoder' ;
27
27
import type CacheableRequest from 'cacheable-request' ;
@@ -47,25 +47,25 @@ type AcceptableResponse = IncomingMessageWithTimings | ResponseLike;
47
47
type AcceptableRequestResult = Promisable < AcceptableResponse | ClientRequest > | undefined ;
48
48
export type RequestFunction = ( url : URL , options : NativeRequestOptions , callback ?: ( response : AcceptableResponse ) => void ) => AcceptableRequestResult ;
49
49
50
- export interface Agents {
50
+ export type Agents = {
51
51
http ?: HttpAgent | false ;
52
52
https ?: HttpsAgent | false ;
53
53
http2 ?: unknown | false ;
54
- }
54
+ } ;
55
55
56
56
export type Headers = Record < string , string | string [ ] | undefined > ;
57
57
58
- export interface ToughCookieJar {
58
+ export type ToughCookieJar = {
59
59
getCookieString : ( ( currentUrl : string , options : Record < string , unknown > , cb : ( error : Error | null , cookies : string ) => void ) => void ) // eslint-disable-line @typescript-eslint/ban-types
60
60
& ( ( url : string , callback : ( error : Error | null , cookieHeader : string ) => void ) => void ) ; // eslint-disable-line @typescript-eslint/ban-types
61
61
setCookie : ( ( cookieOrString : unknown , currentUrl : string , options : Record < string , unknown > , cb : ( error : Error | null , cookie : unknown ) => void ) => void ) // eslint-disable-line @typescript-eslint/ban-types
62
62
& ( ( rawCookie : string , url : string , callback : ( error : Error | null , result : unknown ) => void ) => void ) ; // eslint-disable-line @typescript-eslint/ban-types
63
- }
63
+ } ;
64
64
65
- export interface PromiseCookieJar {
65
+ export type PromiseCookieJar = {
66
66
getCookieString : ( url : string ) => Promise < string > ;
67
67
setCookie : ( rawCookie : string , url : string ) => Promise < unknown > ;
68
- }
68
+ } ;
69
69
70
70
export type InitHook = ( init : OptionsInit , self : Options ) => void ;
71
71
export type BeforeRequestHook = ( options : Options ) => Promisable < void | Response | ResponseLike > ;
@@ -77,7 +77,7 @@ export type AfterResponseHook<ResponseType = unknown> = (response: Response<Resp
77
77
/**
78
78
All available hooks of Got.
79
79
*/
80
- export interface Hooks {
80
+ export type Hooks = {
81
81
/**
82
82
Called with the plain request options, right before their normalization.
83
83
@@ -350,7 +350,7 @@ export interface Hooks {
350
350
```
351
351
*/
352
352
afterResponse : AfterResponseHook [ ] ;
353
- }
353
+ } ;
354
354
355
355
export type ParseJsonFunction = ( text : string ) => unknown ;
356
356
export type StringifyJsonFunction = ( object : unknown ) => string ;
@@ -376,13 +376,13 @@ export type Method =
376
376
| 'options'
377
377
| 'trace' ;
378
378
379
- export interface RetryObject {
379
+ export type RetryObject = {
380
380
attemptCount : number ;
381
381
retryOptions : RetryOptions ;
382
382
error : RequestError ;
383
383
computedValue : number ;
384
384
retryAfter ?: number ;
385
- }
385
+ } ;
386
386
387
387
export type RetryFunction = ( retryObject : RetryObject ) => Promisable < number > ;
388
388
@@ -408,7 +408,7 @@ __Note:__ Got does not retry on `POST` by default.
408
408
__Note:__ If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`.
409
409
__Note:__ If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.
410
410
*/
411
- export interface RetryOptions {
411
+ export type RetryOptions = {
412
412
limit : number ;
413
413
methods : Method [ ] ;
414
414
statusCodes : number [ ] ;
@@ -417,17 +417,17 @@ export interface RetryOptions {
417
417
backoffLimit : number ;
418
418
noise : number ;
419
419
maxRetryAfter ?: number ;
420
- }
420
+ } ;
421
421
422
422
export type CreateConnectionFunction = ( options : NativeRequestOptions , oncreate : ( error : NodeJS . ErrnoException , socket : Socket ) => void ) => Socket ;
423
423
export type CheckServerIdentityFunction = ( hostname : string , certificate : DetailedPeerCertificate ) => NodeJS . ErrnoException | void ;
424
424
425
- export interface CacheOptions {
425
+ export type CacheOptions = {
426
426
shared ?: boolean ;
427
427
cacheHeuristic ?: number ;
428
428
immutableMinTimeToLive ?: number ;
429
429
ignoreCargoCult ?: boolean ;
430
- }
430
+ } ;
431
431
432
432
type PfxObject = {
433
433
buffer : string | Buffer ;
@@ -436,7 +436,7 @@ type PfxObject = {
436
436
437
437
type PfxType = string | Buffer | Array < string | Buffer | PfxObject > | undefined ;
438
438
439
- export interface HttpsOptions {
439
+ export type HttpsOptions = {
440
440
alpnProtocols ?: string [ ] ;
441
441
442
442
// From `http.RequestOptions` and `tls.CommonConnectionOptions`
@@ -497,24 +497,24 @@ export interface HttpsOptions {
497
497
dhparam ?: SecureContextOptions [ 'dhparam' ] ;
498
498
ecdhCurve ?: SecureContextOptions [ 'ecdhCurve' ] ;
499
499
certificateRevocationLists ?: SecureContextOptions [ 'crl' ] ;
500
- }
500
+ } ;
501
501
502
- export interface PaginateData < BodyType , ElementType > {
502
+ export type PaginateData < BodyType , ElementType > = {
503
503
response : Response < BodyType > ;
504
504
currentItems : ElementType [ ] ;
505
505
allItems : ElementType [ ] ;
506
- }
506
+ } ;
507
507
508
- export interface FilterData < ElementType > {
508
+ export type FilterData < ElementType > = {
509
509
item : ElementType ;
510
510
currentItems : ElementType [ ] ;
511
511
allItems : ElementType [ ] ;
512
- }
512
+ } ;
513
513
514
514
/**
515
515
All options accepted by `got.paginate()`.
516
516
*/
517
- export interface PaginationOptions < ElementType , BodyType > {
517
+ export type PaginationOptions < ElementType , BodyType > = {
518
518
/**
519
519
A function that transform [`Response`](#response) into an array of items.
520
520
This is where you should do the parsing.
@@ -619,7 +619,7 @@ export interface PaginationOptions<ElementType, BodyType> {
619
619
@default false
620
620
*/
621
621
stackAllItems ?: boolean ;
622
- }
622
+ } ;
623
623
624
624
export type SearchParameters = Record < string , string | number | boolean | null | undefined > ; // eslint-disable-line @typescript-eslint/ban-types
625
625
@@ -1142,6 +1142,7 @@ export default class Options {
1142
1142
throw new TypeError ( `Unexpected agent option: ${ key } ` ) ;
1143
1143
}
1144
1144
1145
+ // @ts -expect-error - No idea why `value[key]` doesn't work here.
1145
1146
assert . any ( [ is . object , is . undefined ] , value [ key ] ) ;
1146
1147
}
1147
1148
@@ -1210,6 +1211,7 @@ export default class Options {
1210
1211
throw new Error ( `Unexpected timeout option: ${ key } ` ) ;
1211
1212
}
1212
1213
1214
+ // @ts -expect-error - No idea why `value[key]` doesn't work here.
1213
1215
assert . any ( [ is . number , is . undefined ] , value [ key ] ) ;
1214
1216
}
1215
1217
@@ -1732,8 +1734,7 @@ export default class Options {
1732
1734
}
1733
1735
1734
1736
const typedKnownHookEvent = knownHookEvent as keyof Hooks ;
1735
- const typedValue = value as Hooks ;
1736
- const hooks = typedValue [ typedKnownHookEvent ] ;
1737
+ const hooks = value [ typedKnownHookEvent ] ;
1737
1738
1738
1739
assert . any ( [ is . array , is . undefined ] , hooks ) ;
1739
1740
0 commit comments