Skip to content

Commit b24e5f6

Browse files
authored
Add undefined to optional properties, Express to He (#54321)
In preparation for exactOptionalPropertyTypes in Typescript 4.4, add undefined to all optional properties. #no-publishing-comment This PR covers widely used packages (more than 100,000 downloads per month) from express-rate-limit -- he. microsoft/dtslint#335
1 parent f123831 commit b24e5f6

127 files changed

Lines changed: 4970 additions & 4954 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

types/express-rate-limit/index.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare namespace rateLimit {
3131
readonly limit: number;
3232
readonly current: number;
3333
readonly remaining: number;
34-
readonly resetTime?: Date;
34+
readonly resetTime?: Date | undefined;
3535
}
3636

3737
type StoreIncrementCallback = (err?: {}, hits?: number, resetTime?: Date) => void;
@@ -65,15 +65,15 @@ declare namespace rateLimit {
6565
* Enable headers for request limit (`X-RateLimit-Limit`) and current usage (`X-RateLimit-Remaining`) on all
6666
* responses and time to wait before retrying (`Retry-After`) when `max` is exceeded. Defaults to `true`.
6767
*/
68-
headers?: boolean;
68+
headers?: boolean | undefined;
6969

7070
/**
7171
* Enable headers conforming to the [ratelimit standardization proposal](https://tools.ietf.org/id/draft-polli-ratelimit-headers-01.html):
7272
* `RateLimit-Limit`, `RateLimit-Remaining`, and, if the store supports it, `RateLimit-Reset`. May be used in conjunction with, or instead of the `headers` option.
7373
* Behavior and name will likely change in future releases.
7474
* @default false
7575
*/
76-
draft_polli_ratelimit_headers?: boolean;
76+
draft_polli_ratelimit_headers?: boolean | undefined;
7777

7878
/**
7979
* Function used to generate keys. Defaults to using `req.ip`.
@@ -87,13 +87,13 @@ declare namespace rateLimit {
8787
* Set to `0` to disable.
8888
* @default 5
8989
*/
90-
max?: number | MaxValueFn;
90+
max?: number | MaxValueFn | undefined;
9191

9292
/**
9393
* Error message sent to user when `max` is exceeded. May be a `string`, JSON object, or any other value
9494
* that Express's `req.send()` supports. Defaults to `'Too many requests, please try again later.'`.
9595
*/
96-
message?: string | Buffer | Message;
96+
message?: string | Buffer | Message | undefined;
9797

9898
/**
9999
* Function that is called the first time `max` is exceeded. The `req.rateLimit` object has `limit`, `current`,
@@ -113,30 +113,30 @@ declare namespace rateLimit {
113113
/**
114114
* When set to `true`, failed requests (status >= 400, request canceled or errored) won't be counted. Defaults to `false`.
115115
*/
116-
skipFailedRequests?: boolean;
116+
skipFailedRequests?: boolean | undefined;
117117

118118
/**
119119
* When set to `true`, successful requests (status < 400) won't be counted. Defaults to `false`.
120120
*/
121-
skipSuccessfulRequests?: boolean;
121+
skipSuccessfulRequests?: boolean | undefined;
122122

123123
/**
124124
* HTTP status code returned when `max` is exceeded. Defaults to `429`.
125125
*/
126-
statusCode?: number;
126+
statusCode?: number | undefined;
127127

128128
/**
129129
* The storage to use when persisting rate limit attempts.
130130
*/
131-
store?: Store;
131+
store?: Store | undefined;
132132

133133
/**
134134
* Timeframe for which requests are checked/remembered. Also used in the Retry-After header when the limit is reached.
135135
* Note: with non-default stores, you may need to configure this value twice, once here and once on the store.
136136
* In some cases the units also differ (e.g. seconds vs miliseconds)
137137
* @default 60000
138138
*/
139-
windowMs?: number;
139+
windowMs?: number | undefined;
140140
}
141141
}
142142

types/express-rate-limit/v2/index.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ declare namespace RateLimit {
2222
}
2323

2424
interface Options {
25-
delayAfter?: number;
26-
delayMs?: number;
25+
delayAfter?: number | undefined;
26+
delayMs?: number | undefined;
2727
handler?(req: express.Request, res: express.Response, next: express.NextFunction): any;
28-
headers?: boolean;
28+
headers?: boolean | undefined;
2929
keyGenerator?(req: express.Request, res: express.Response): string;
30-
max?: number;
31-
message?: string | Buffer | Message;
30+
max?: number | undefined;
31+
message?: string | Buffer | Message | undefined;
3232
skip?(req: express.Request, res: express.Response): boolean;
33-
skipFailedRequests?: boolean;
34-
statusCode?: number;
35-
store?: Store;
33+
skipFailedRequests?: boolean | undefined;
34+
statusCode?: number | undefined;
35+
store?: Store | undefined;
3636
onLimitReached?(req: express.Request, res: express.Response, optionsUsed: Options): void;
37-
windowMs?: number;
37+
windowMs?: number | undefined;
3838
}
3939

4040
interface Instance extends express.RequestHandler {

types/express-rate-limit/v3/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ declare namespace RateLimit {
3939
* Enable headers for request limit (`X-RateLimit-Limit`) and current usage (`X-RateLimit-Remaining`) on all
4040
* responses andtime to wait before retrying (`Retry-After`) when `max` is exceeded. Defaults to `true`.
4141
*/
42-
headers?: boolean;
42+
headers?: boolean | undefined;
4343

4444
/**
4545
* Function used to generate keys. Defaults to using `req.ip`.
@@ -51,13 +51,13 @@ declare namespace RateLimit {
5151
* Max number of connections during `windowMs` before sending a 429 response. May be a `number` or
5252
* a function that returns a `number` or a `Promise<number>`. Defaults to `5`. Set to `0` to disable.
5353
*/
54-
max?: number | MaxValueFn;
54+
max?: number | MaxValueFn | undefined;
5555

5656
/**
5757
* Error message sent to user when `max` is exceeded. May be a `string`, JSON object, or any other value
5858
* that Express's `req.send()` supports. Defaults to `'Too many requests, please try again later.'`.
5959
*/
60-
message?: string | Buffer | Message;
60+
message?: string | Buffer | Message | undefined;
6161

6262
/**
6363
* Function that is called the first time `max` is exceeded. The `req.rateLimit` object has `limit`, `current`,
@@ -77,27 +77,27 @@ declare namespace RateLimit {
7777
/**
7878
* When set to `true`, failed requests (status >= 400, request canceled or errored) won't be counted. Defaults to `false`.
7979
*/
80-
skipFailedRequests?: boolean;
80+
skipFailedRequests?: boolean | undefined;
8181

8282
/**
8383
* When set to `true`, successful requests (status < 400) won't be counted. Defaults to `false`.
8484
*/
85-
skipSuccessfulRequests?: boolean;
85+
skipSuccessfulRequests?: boolean | undefined;
8686

8787
/**
8888
* HTTP status code returned when `max` is exceeded. Defaults to `429`.
8989
*/
90-
statusCode?: number;
90+
statusCode?: number | undefined;
9191

9292
/**
9393
* The storage to use when persisting rate limit attempts.
9494
*/
95-
store?: Store;
95+
store?: Store | undefined;
9696

9797
/**
9898
* How long in milliseconds to keep records of requests in memory. Defaults to `60000` (1 minute).
9999
*/
100-
windowMs?: number;
100+
windowMs?: number | undefined;
101101
}
102102
interface Instance extends express.RequestHandler {
103103
resetKey(key: string): void;

types/express-serve-static-core/index.d.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,15 @@ export interface IRoute<Route extends string = string> {
328328
export interface Router extends IRouter {}
329329

330330
export interface CookieOptions {
331-
maxAge?: number;
332-
signed?: boolean;
333-
expires?: Date;
334-
httpOnly?: boolean;
335-
path?: string;
336-
domain?: string;
337-
secure?: boolean;
338-
encode?: (val: string) => string;
339-
sameSite?: boolean | 'lax' | 'strict' | 'none';
331+
maxAge?: number | undefined;
332+
signed?: boolean | undefined;
333+
expires?: Date | undefined;
334+
httpOnly?: boolean | undefined;
335+
path?: string | undefined;
336+
domain?: string | undefined;
337+
secure?: boolean | undefined;
338+
encode?: ((val: string) => string) | undefined;
339+
sameSite?: boolean | 'lax' | 'strict' | 'none' | undefined;
340340
}
341341

342342
export interface ByteRange {
@@ -640,8 +640,8 @@ export interface Request<
640640
* After middleware.init executed, Request will contain res and next properties
641641
* See: express/lib/middleware/init.js
642642
*/
643-
res?: Response<ResBody, Locals>;
644-
next?: NextFunction;
643+
res?: Response<ResBody, Locals> | undefined;
644+
next?: NextFunction | undefined;
645645
}
646646

647647
export interface MediaType {

types/express-session/index.d.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ declare namespace session {
7676
* then you need to separate the session cookies from each other.
7777
* The simplest method is to simply set different names per app.
7878
*/
79-
name?: string;
79+
name?: string | undefined;
8080

8181
/**
8282
* The session store instance, defaults to a new `MemoryStore` instance.
8383
* @see MemoryStore
8484
*/
85-
store?: Store;
85+
store?: Store | undefined;
8686

8787
/**
8888
* Settings object for the session ID cookie.
8989
* @see CookieOptions
9090
*/
91-
cookie?: CookieOptions;
91+
cookie?: CookieOptions | undefined;
9292

9393
/**
9494
* Force the session identifier cookie to be set on every response. The expiration is reset to the original `maxAge`, resetting the expiration countdown.
@@ -103,7 +103,7 @@ declare namespace session {
103103
*
104104
* @see saveUninitialized
105105
*/
106-
rolling?: boolean;
106+
rolling?: boolean | undefined;
107107

108108
/**
109109
* Forces the session to be saved back to the session store, even if the session was never modified during the request.
@@ -117,7 +117,7 @@ declare namespace session {
117117
* If it does, then you can safely set `resave: false`.
118118
* If it does not implement the `touch` method and your store sets an expiration date on stored sessions, then you likely need `resave: true`.
119119
*/
120-
resave?: boolean;
120+
resave?: boolean | undefined;
121121

122122
/**
123123
* Trust the reverse proxy when setting secure cookies (via the "X-Forwarded-Proto" header).
@@ -127,7 +127,7 @@ declare namespace session {
127127
* - `false`: All headers are ignored and the connection is considered secure only if there is a direct TLS/SSL connection.
128128
* - `undefined`: Uses the "trust proxy" setting from express
129129
*/
130-
proxy?: boolean;
130+
proxy?: boolean | undefined;
131131

132132
/**
133133
* Forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified.
@@ -141,15 +141,15 @@ declare namespace session {
141141
* Passport will add an empty Passport object to the session for use after a user is authenticated, which will be treated as a modification to the session, causing it to be saved.
142142
* This has been fixed in PassportJS 0.3.0.
143143
*/
144-
saveUninitialized?: boolean;
144+
saveUninitialized?: boolean | undefined;
145145

146146
/**
147147
* Control the result of unsetting req.session (through delete, setting to null, etc.).
148148
* - `destroy`: The session will be destroyed (deleted) when the response ends.
149149
* - `keep`: The session in the store will be kept, but modifications made during the request are ignored and not saved.
150150
* @default 'keep'
151151
*/
152-
unset?: 'destroy' | 'keep';
152+
unset?: 'destroy' | 'keep' | undefined;
153153
}
154154

155155
class Session {
@@ -224,9 +224,9 @@ declare namespace session {
224224
*
225225
* @see expires
226226
*/
227-
maxAge?: number;
227+
maxAge?: number | undefined;
228228

229-
signed?: boolean;
229+
signed?: boolean | undefined;
230230

231231
/**
232232
* Specifies the `Date` object to be the value for the `Expires Set-Cookie` attribute.
@@ -237,27 +237,27 @@ declare namespace session {
237237
* @deprecated The `expires` option should not be set directly; instead only use the `maxAge` option
238238
* @see maxAge
239239
*/
240-
expires?: Date;
240+
expires?: Date | undefined;
241241

242242
/**
243243
* Specifies the boolean value for the `HttpOnly Set-Cookie` attribute. When truthy, the `HttpOnly` attribute is set, otherwise it is not.
244244
* By default, the `HttpOnly` attribute is set.
245245
*
246246
* Be careful when setting this to `true`, as compliant clients will not allow client-side JavaScript to see the cookie in `document.cookie`.
247247
*/
248-
httpOnly?: boolean;
248+
httpOnly?: boolean | undefined;
249249

250250
/**
251251
* Specifies the value for the `Path Set-Cookie` attribute.
252252
* By default, this is set to '/', which is the root path of the domain.
253253
*/
254-
path?: string;
254+
path?: string | undefined;
255255

256256
/**
257257
* Specifies the value for the `Domain Set-Cookie` attribute.
258258
* By default, no domain is set, and most clients will consider the cookie to apply to only the current domain.
259259
*/
260-
domain?: string;
260+
domain?: string | undefined;
261261

262262
/**
263263
* Specifies the boolean value for the `Secure Set-Cookie` attribute. When truthy, the `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
@@ -275,9 +275,9 @@ declare namespace session {
275275
*
276276
* Please see the [README](https://github.com/expressjs/session) for an example of using secure cookies in production, but allowing for testing in development based on NODE_ENV.
277277
*/
278-
secure?: boolean | 'auto';
278+
secure?: boolean | 'auto' | undefined;
279279

280-
encode?: (val: string) => string;
280+
encode?: ((val: string) => string) | undefined;
281281

282282
/**
283283
* Specifies the boolean or string to be the value for the `SameSite Set-Cookie` attribute.
@@ -292,21 +292,21 @@ declare namespace session {
292292
* **Note:** This is an attribute that has not yet been fully standardized, and may change in the future.
293293
* This also means many clients may ignore this attribute until they understand it.
294294
*/
295-
sameSite?: boolean | 'lax' | 'strict' | 'none';
295+
sameSite?: boolean | 'lax' | 'strict' | 'none' | undefined;
296296
}
297297

298298
class Cookie implements CookieOptions {
299299
/** Returns the original `maxAge` (time-to-live), in milliseconds, of the session cookie. */
300300
originalMaxAge: number;
301301

302-
maxAge?: number;
303-
signed?: boolean;
304-
expires?: Date;
305-
httpOnly?: boolean;
306-
path?: string;
307-
domain?: string;
308-
secure?: boolean | 'auto';
309-
sameSite?: boolean | 'lax' | 'strict' | 'none';
302+
maxAge?: number | undefined;
303+
signed?: boolean | undefined;
304+
expires?: Date | undefined;
305+
httpOnly?: boolean | undefined;
306+
path?: string | undefined;
307+
domain?: string | undefined;
308+
secure?: boolean | 'auto' | undefined;
309+
sameSite?: boolean | 'lax' | 'strict' | 'none' | undefined;
310310
}
311311

312312
abstract class Store extends EventEmitter {

types/express-unless/index.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ declare function unless(options: unless.Options): express.RequestHandler;
1212
declare function unless(options: unless.Options["custom"]): express.RequestHandler;
1313

1414
declare namespace unless {
15-
type pathFilter = string | RegExp | { url: string | RegExp, methods?: string[], method?: string | string[] };
15+
type pathFilter = string | RegExp | { url: string | RegExp, methods?: string[] | undefined, method?: string | string[] | undefined };
1616

1717
export interface Options {
18-
custom?: (req: express.Request) => boolean;
19-
path?: pathFilter | pathFilter[];
20-
ext?: string | string[];
21-
method?: string | string[];
22-
useOriginalUrl?: boolean;
18+
custom?: ((req: express.Request) => boolean) | undefined;
19+
path?: pathFilter | pathFilter[] | undefined;
20+
ext?: string | string[] | undefined;
21+
method?: string | string[] | undefined;
22+
useOriginalUrl?: boolean | undefined;
2323
}
2424
export interface RequestHandler extends express.RequestHandler {
25-
unless?: typeof unless;
25+
unless?: typeof unless | undefined;
2626
}
2727
}
2828

0 commit comments

Comments
 (0)