@@ -66,9 +66,9 @@ export interface Agents {
66
66
export const withoutBody : ReadonlySet < string > = new Set ( [ 'GET' , 'HEAD' ] ) ;
67
67
68
68
export interface ToughCookieJar {
69
- getCookieString : ( ( currentUrl : string , options : { [ key : string ] : unknown } , cb : ( err : Error | null , cookies : string ) => void ) => void )
69
+ getCookieString : ( ( currentUrl : string , options : Record < string , unknown > , cb : ( err : Error | null , cookies : string ) => void ) => void )
70
70
& ( ( url : string , callback : ( error : Error | null , cookieHeader : string ) => void ) => void ) ;
71
- setCookie : ( ( cookieOrString : unknown , currentUrl : string , options : { [ key : string ] : unknown } , cb : ( err : Error | null , cookie : unknown ) => void ) => void )
71
+ setCookie : ( ( cookieOrString : unknown , currentUrl : string , options : Record < string , unknown > , cb : ( err : Error | null , cookie : unknown ) => void ) => void )
72
72
& ( ( rawCookie : string , url : string , callback : ( error : Error | null , result : unknown ) => void ) => void ) ;
73
73
}
74
74
@@ -250,7 +250,7 @@ export type RequestFunction = (url: URL, options: RequestOptions, callback?: (re
250
250
export type Headers = Record < string , string | string [ ] | undefined > ;
251
251
252
252
type CacheableRequestFunction = (
253
- opts : string | URL | RequestOptions ,
253
+ options : string | URL | RequestOptions ,
254
254
cb ?: ( response : ServerResponse | ResponseLike ) => void
255
255
) => CacheableRequest . Emitter ;
256
256
@@ -436,7 +436,7 @@ interface PlainOptions extends URLOptions {
436
436
437
437
__Note #2__: This option is not enumerable and will not be merged with the instance defaults.
438
438
*/
439
- form ?: { [ key : string ] : any } ;
439
+ form ?: Record < string , any > ;
440
440
441
441
/**
442
442
JSON body. If the `Content-Type` header is not set, it will be set to `application/json`.
@@ -445,7 +445,7 @@ interface PlainOptions extends URLOptions {
445
445
446
446
__Note #2__: This option is not enumerable and will not be merged with the instance defaults.
447
447
*/
448
- json ?: { [ key : string ] : any } ;
448
+ json ?: Record < string , any > ;
449
449
450
450
/**
451
451
The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
@@ -500,7 +500,7 @@ interface PlainOptions extends URLOptions {
500
500
//=> 'key=a&key=b'
501
501
```
502
502
*/
503
- searchParams ?: string | { [ key : string ] : string | number | boolean | null | undefined } | URLSearchParams ;
503
+ searchParams ?: string | Record < string , string | number | boolean | null | undefined > | URLSearchParams ;
504
504
505
505
/**
506
506
An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
@@ -1805,7 +1805,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
1805
1805
for ( const event of knownHookEvents ) {
1806
1806
const defaultHooks = defaults . hooks [ event ] ;
1807
1807
1808
- if ( defaultHooks . length !== 0 ) {
1808
+ if ( defaultHooks . length > 0 ) {
1809
1809
// See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
1810
1810
( options . hooks as any ) [ event ] = [
1811
1811
...defaults . hooks [ event ] ,
@@ -2206,11 +2206,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
2206
2206
// Node.js <= 12.18.2 mistakenly emits the response `end` first.
2207
2207
( request as ClientRequest & { res : IncomingMessage | undefined } ) . res ?. removeAllListeners ( 'end' ) ;
2208
2208
2209
- if ( error instanceof TimedOutTimeoutError ) {
2210
- error = new TimeoutError ( error , this . timings ! , this ) ;
2211
- } else {
2212
- error = new RequestError ( error . message , error , this ) ;
2213
- }
2209
+ error = error instanceof TimedOutTimeoutError ? new TimeoutError ( error , this . timings ! , this ) : new RequestError ( error . message , error , this ) ;
2214
2210
2215
2211
this . _beforeError ( error as RequestError ) ;
2216
2212
} ) ;
@@ -2652,7 +2648,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
2652
2648
// TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
2653
2649
2654
2650
this [ kRequest ] ! . write ( chunk , encoding ! , ( error ?: Error | null ) => {
2655
- if ( ! error && this . _progressCallbacks . length !== 0 ) {
2651
+ if ( ! error && this . _progressCallbacks . length > 0 ) {
2656
2652
this . _progressCallbacks . shift ( ) ! ( ) ;
2657
2653
}
2658
2654
@@ -2729,7 +2725,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
2729
2725
The remote IP address.
2730
2726
*/
2731
2727
get ip ( ) : string | undefined {
2732
- return this [ kRequest ] ? .socket . remoteAddress ;
2728
+ return this . socket ? .remoteAddress ;
2733
2729
}
2734
2730
2735
2731
/**
@@ -2740,7 +2736,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
2740
2736
}
2741
2737
2742
2738
get socket ( ) : Socket | undefined {
2743
- return this [ kRequest ] ?. socket ;
2739
+ return this [ kRequest ] ?. socket ?? undefined ;
2744
2740
}
2745
2741
2746
2742
/**
0 commit comments