Skip to content

Commit d280918

Browse files
authored
Merge pull request #1511 from clearlydefined/typescript-phase1-reduce-any
Replace any with proper types in .d.ts files, fix export type error
2 parents 705cc31 + 0993bdd commit d280918

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

lib/fetch.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface FetchRequestOptions {
2121
/** HTTP headers to include in the request. */
2222
headers?: Record<string, string>
2323
/** Request body data. */
24-
body?: any
24+
body?: unknown
2525
/** Whether to include credentials in cross-origin requests. */
2626
withCredentials?: boolean
2727
/** Whether to throw an error for HTTP error status codes. Defaults to `true`. */
@@ -36,8 +36,6 @@ export interface FetchResponse<T = any> extends AxiosResponse<T> {
3636
statusCode: number
3737
/** HTTP status message (alias for `statusText`). */
3838
statusMessage: string
39-
/** Response configuration used for the request. */
40-
config: any
4139
}
4240

4341
/** HTTP error with status code information. */

lib/rateLimit.d.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// SPDX-License-Identifier: MIT
33

44
import type { NextFunction, Request, Response } from 'express'
5-
import type { Store } from 'express-rate-limit'
5+
import type { Options as ExpressRateLimitOptions, Store } from 'express-rate-limit'
6+
import type { RedisClientType } from 'redis'
67
import type { ICache } from '../providers/caching'
78
import type { Logger } from '../providers/logging'
89

@@ -33,7 +34,7 @@ export interface ExtendedRateLimitConfig extends LegacyRateLimitConfig {
3334
/** Redis-specific configuration for rate limiting */
3435
export interface RedisRateLimitConfig {
3536
/** Redis client instance */
36-
client: any
37+
client: RedisClientType
3738
/** Prefix for Redis keys used by the rate limiter */
3839
prefix: string
3940
}
@@ -67,7 +68,7 @@ export type RateLimitMiddleware = (req: Request, res: Response, next: NextFuncti
6768
/** Base rate limiter class that provides rate limiting functionality using express-rate-limit */
6869
declare class RateLimiter {
6970
/** Configuration options for the rate limiter */
70-
protected options: any
71+
protected options: RateLimiterOptions
7172

7273
/** Logger instance for rate limiter operations */
7374
protected logger: Logger
@@ -80,7 +81,7 @@ declare class RateLimiter {
8081
*
8182
* @param opts - Configuration options for the rate limiter
8283
*/
83-
constructor(opts: any)
84+
constructor(opts: RateLimiterOptions)
8485

8586
/**
8687
* Initializes the rate limiter with optional store
@@ -104,20 +105,20 @@ declare class RateLimiter {
104105
* @param store - Optional store for rate limit data persistence
105106
* @returns Options object for express-rate-limit
106107
*/
107-
static buildOptions(config: any, store?: Store): any
108+
static buildOptions(config: RateLimitConfig, store?: Store): Partial<ExpressRateLimitOptions>
108109
}
109110

110111
/** Redis-based rate limiter that extends RateLimiter with Redis persistence */
111112
declare class RedisBasedRateLimiter extends RateLimiter {
112113
/** Redis client instance */
113-
private _client: any
114+
private _client: RedisClientType | undefined
114115

115116
/**
116117
* Creates a new RedisBasedRateLimiter instance
117118
*
118119
* @param opts - Configuration options including Redis client
119120
*/
120-
constructor(opts: any)
121+
constructor(opts: RateLimiterOptions)
121122

122123
/**
123124
* Initializes the Redis-based rate limiter
@@ -134,13 +135,13 @@ declare class RedisBasedRateLimiter extends RateLimiter {
134135
* @param config - Redis configuration with prefix
135136
* @returns Redis store instance for express-rate-limit
136137
*/
137-
static buildRedisStore(client: any, config: any): Store
138+
static buildRedisStore(client: RedisClientType, config: RedisRateLimitConfig): Store
138139
}
139140

140141
/** Abstract base class for middleware delegates that create rate limiting middleware asynchronously */
141142
declare abstract class AbstractMiddlewareDelegate {
142143
/** Configuration options for the middleware delegate */
143-
protected options: any
144+
protected options: RateLimiterFactoryOptions
144145

145146
/** Logger instance for middleware operations */
146147
protected logger: Logger
@@ -153,7 +154,7 @@ declare abstract class AbstractMiddlewareDelegate {
153154
*
154155
* @param opts - Configuration options for the middleware delegate
155156
*/
156-
constructor(opts: any)
157+
constructor(opts: RateLimiterFactoryOptions)
157158

158159
/**
159160
* Gets the rate limiting middleware function
@@ -203,7 +204,7 @@ declare class BatchApiMiddlewareDelegate extends AbstractMiddlewareDelegate {
203204
* @param opts - Configuration options for the rate limiter
204205
* @returns RateLimiter or RedisBasedRateLimiter instance
205206
*/
206-
declare function createRateLimiter(opts: any): RateLimiter | RedisBasedRateLimiter
207+
declare function createRateLimiter(opts: RateLimiterOptions): RateLimiter | RedisBasedRateLimiter
207208

208209
/**
209210
* Builds rate limiter options from configuration
@@ -214,7 +215,12 @@ declare function createRateLimiter(opts: any): RateLimiter | RedisBasedRateLimit
214215
* @param logger - Logger instance
215216
* @returns Rate limiter options
216217
*/
217-
declare function buildOpts(config: LegacyRateLimitConfig, cachingService: ICache, prefix: string, logger?: Logger): any
218+
declare function buildOpts(
219+
config: LegacyRateLimitConfig,
220+
cachingService: ICache,
221+
prefix: string,
222+
logger?: Logger
223+
): RateLimiterOptions
218224

219225
/**
220226
* Creates an API rate limiter instance
@@ -241,8 +247,8 @@ declare function createBatchApiLimiter(options?: RateLimiterFactoryOptions): Rat
241247
* @returns Express middleware function for API rate limiting
242248
*/
243249
declare function setupApiRateLimiterAfterCachingInit(
244-
config: any,
245-
cachingService: any,
250+
config: RateLimiterFactoryOptions['config'],
251+
cachingService: ICache,
246252
logger?: Logger
247253
): RateLimitMiddleware
248254

@@ -255,8 +261,8 @@ declare function setupApiRateLimiterAfterCachingInit(
255261
* @returns Express middleware function for batch API rate limiting
256262
*/
257263
declare function setupBatchApiRateLimiterAfterCachingInit(
258-
config: any,
259-
cachingService: any,
264+
config: RateLimiterFactoryOptions['config'],
265+
cachingService: ICache,
260266
logger?: Logger
261267
): RateLimitMiddleware
262268

providers/search/abstractSearch.d.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license.
22
// SPDX-License-Identifier: MIT
33

4+
import type { Definition } from '../../business/definitionService'
5+
import type { EntityCoordinates } from '../../lib/entityCoordinates'
6+
47
export interface SearchOptions {
58
[key: string]: any
69
}
@@ -14,25 +17,25 @@ export declare class AbstractSearch {
1417
initialize(): Promise<void>
1518

1619
/** Look up a result by coordinates. */
17-
get(coordinates: any): Promise<any>
20+
get(coordinates: EntityCoordinates): Promise<Definition | null>
1821

1922
/** Suggest coordinates matching a pattern. */
2023
suggestCoordinates(pattern: string): Promise<string[]>
2124

2225
/** Add one or more definitions to the search index. */
23-
store(definition: any): void
26+
store(definition: Definition): void
2427

2528
/** Query the search index. */
26-
query(body: any): any
29+
query(body: Record<string, unknown>): unknown
2730

2831
/** Remove a definition from the search index by coordinates. */
29-
delete(coordinates: any): void
32+
delete(coordinates: EntityCoordinates): void
3033

3134
/** Extract unique license expressions from a definition's facets. */
32-
protected _getLicenses(definition: any): string[]
35+
protected _getLicenses(definition: Definition): string[]
3336

3437
/** Extract unique attribution parties from a definition's facets. */
35-
protected _getAttributions(definition: any): string[]
38+
protected _getAttributions(definition: Definition): string[]
3639
}
3740

3841
export default AbstractSearch

types/winston-azure-application-insights.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
declare module 'winston-azure-application-insights' {
9-
import type * as winston from 'winston'
109
import type * as appInsights from 'applicationinsights'
10+
import type * as winston from 'winston'
1111

1212
/** Winston log levels mapped to Application Insights severity levels. */
1313
type WinstonLevel =
@@ -117,5 +117,5 @@ declare module 'winston-azure-application-insights' {
117117

118118
// Export the transport constructor for use with winston.add()
119119
export const AzureApplicationInsightsLogger: AzureApplicationInsightsLoggerConstructor
120-
export { getMessageLevel, defaultFormatter }
120+
export type { defaultFormatter, getMessageLevel }
121121
}

0 commit comments

Comments
 (0)