Skip to content

Commit 5111f82

Browse files
heiskrCopilot
andauthored
Remove some 'any' types from 4 files (#61660)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 620875b commit 5111f82

5 files changed

Lines changed: 25 additions & 17 deletions

File tree

eslint.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,16 @@ export default [
234234
// Legacy files with @typescript-eslint/no-explicit-any violations (see github/docs-engineering#5797)
235235
{
236236
files: [
237-
'src/article-api/transformers/audit-logs-transformer.ts',
238237
'src/article-api/transformers/rest-transformer.ts',
239238
'src/content-render/unified/annotate.ts',
240239
'src/frame/components/context/MainContext.tsx',
241240
'src/landings/components/CookBookFilter.tsx',
242241
'src/languages/lib/correct-translation-content.ts',
243-
'src/languages/lib/render-with-fallback.ts',
244242
'src/search/components/hooks/useAISearchAutocomplete.ts',
245243
'src/search/components/hooks/useAISearchLocalStorageCache.ts',
246244
'src/search/components/input/SearchOverlay.tsx',
247245
'src/search/lib/get-elasticsearch-results/ai-search-autocomplete.ts',
248246
'src/search/lib/get-elasticsearch-results/general-search.ts',
249-
'src/search/lib/routes/combined-search-route.ts',
250-
'src/search/lib/search-request-params/get-search-from-request-params.ts',
251247
'src/search/scripts/index/index-cli.ts',
252248
'src/search/scripts/index/utils/indexing-elasticsearch-utils.ts',
253249
],

src/article-api/transformers/audit-logs-transformer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Context, Page } from '@/types'
22
import type { PageTransformer } from './types'
33
import type { CategorizedEvents } from '@/audit-logs/types'
4+
import type { TitleResolutionContext } from '@/audit-logs/lib/index'
45
import { renderContent } from '@/content-render/index'
56
import { loadTemplate } from '@/article-api/lib/load-template'
67
import matter from '@gr2m/gray-matter'
@@ -94,7 +95,10 @@ export class AuditLogsTransformer implements PageTransformer {
9495
categoryNotes: Record<string, string>,
9596
context: Context,
9697
manualContent: string,
97-
resolveReferenceLinksToMarkdown: (docsReferenceLinks: string, context: any) => Promise<string>,
98+
resolveReferenceLinksToMarkdown: (
99+
docsReferenceLinks: string,
100+
context: TitleResolutionContext,
101+
) => Promise<string>,
98102
): Promise<Record<string, unknown>> {
99103
// Prepare page intro
100104
const intro = page.intro ? await page.renderProp('intro', context, { textOnly: true }) : ''
@@ -115,7 +119,7 @@ export class AuditLogsTransformer implements PageTransformer {
115119
if (newEvent.docs_reference_links && newEvent.docs_reference_links !== 'N/A') {
116120
newEvent.docs_reference_links = await resolveReferenceLinksToMarkdown(
117121
newEvent.docs_reference_links,
118-
context,
122+
context as TitleResolutionContext,
119123
)
120124
}
121125
if (newEvent.fields) {

src/languages/lib/render-with-fallback.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { renderContent } from '@/content-render/index'
22
import Page from '@/frame/lib/page'
33
import { TitleFromAutotitleError } from '@/content-render/unified/rewrite-local-links'
4-
import type { Context } from '@/types'
4+
import type { Context, Page as PageType } from '@/types'
55

66
export class EmptyTitleError extends Error {}
77

@@ -31,8 +31,8 @@ export class LiquidError extends Error {
3131
interface RenderOptions {
3232
throwIfEmpty?: boolean
3333
textOnly?: boolean
34-
cache?: boolean | ((template: string, context: any) => string)
35-
[key: string]: any
34+
cache?: boolean | ((template: string, context: Context) => string)
35+
[key: string]: unknown
3636
}
3737

3838
const LIQUID_ERROR_NAMES = new Set(['RenderError', 'ParseError', 'TokenizationError'])
@@ -117,9 +117,10 @@ export function createTranslationFallbackComment(error: Error, property: string)
117117
// higher level than `lib/`) how to use the URL to figure out the
118118
// equivalent English page instance.
119119
export async function renderContentWithFallback(
120-
// Using `any` type for page because the actual Page class from @/frame/lib/page
121-
// has more properties than the Page interface defined in @/types, causing type conflicts
122-
page: any,
120+
// Typed as the @/types Page interface (not the Page class) for caller
121+
// compatibility. The runtime contract is stricter: the value must be an
122+
// actual Page instance (enforced by the `page instanceof Page` check below).
123+
page: PageType,
123124
property: string,
124125
context: Context,
125126
options?: RenderOptions,
@@ -130,7 +131,7 @@ export async function renderContentWithFallback(
130131
if (typeof property !== 'string') {
131132
throw new Error(`The second argument has to be a string (not ${typeof property})`)
132133
}
133-
const template = (page as any)[property] as string
134+
const template = (page as unknown as Record<string, string>)[property]
134135
try {
135136
const output = await renderContent(template, context, options)
136137
if (options && options.throwIfEmpty && !output.trim()) {
@@ -142,7 +143,7 @@ export async function renderContentWithFallback(
142143
// on English for.
143144
if (isFallbackableError(error) && context.getEnglishPage) {
144145
const enPage = context.getEnglishPage(context)
145-
const englishTemplate = (enPage as any)[property] as string
146+
const englishTemplate = (enPage as unknown as Record<string, string>)[property]
146147
// If you don't change the context, it'll confuse the liquid plugins
147148
// like `data.ts` that uses `environment.scope.currentLanguage`
148149
const enContext = Object.assign({}, context, { currentLanguage: 'en' })

src/search/lib/routes/combined-search-route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ export async function combinedSearchRoute(req: Request, res: Response) {
7575
})
7676
} else {
7777
generalSearchPromise = Promise.resolve({
78-
meta: {} as any,
78+
meta: {
79+
found: { value: 0, relation: 'eq' },
80+
took: { query_msec: 0, total_msec: 0 },
81+
// Mirror the requested page size so downstream page-count math
82+
// (which divides by meta.size) stays finite for the empty branch.
83+
size: GENERAL_RESULTS_SIZE,
84+
page: 1,
85+
},
7986
hits: [],
8087
})
8188
}

src/search/lib/search-request-params/get-search-from-request-params.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function getSearchFromRequestParams<Type extends SearchTypes>(
3333

3434
for (const { key, default_, cast, validate, multiple } of searchParamsObject) {
3535
if (key in forceParams) {
36-
;(searchParams[key] as any) = forceParams[key] as any
36+
;(searchParams[key] as unknown) = forceParams[key]
3737
continue
3838
}
3939

@@ -69,7 +69,7 @@ export function getSearchFromRequestParams<Type extends SearchTypes>(
6969
})
7070
}
7171

72-
;(searchParams[key] as any) = value
72+
;(searchParams[key] as unknown) = value
7373
}
7474

7575
let indexName = ''

0 commit comments

Comments
 (0)