Remove 'any' types from 14 files (#58716)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createContext, useContext } from 'react'
|
||||
import pick from 'lodash/pick'
|
||||
import type { ExtendedRequest } from '@/types'
|
||||
|
||||
export type LearningTrack = {
|
||||
trackName: string
|
||||
@@ -38,24 +39,45 @@ export const useProductGuidesContext = (): ProductGuidesContextT => {
|
||||
return context
|
||||
}
|
||||
|
||||
export const getProductGuidesContextFromRequest = (req: any): ProductGuidesContextT => {
|
||||
const page = req.context.page
|
||||
export const getProductGuidesContextFromRequest = (req: ExtendedRequest): ProductGuidesContextT => {
|
||||
if (!req.context || !req.context.page) {
|
||||
throw new Error('Request context or page is missing')
|
||||
}
|
||||
|
||||
const learningTracks: LearningTrack[] = (page.learningTracks || []).map((track: any) => ({
|
||||
...pick(track, ['title', 'description', 'trackName', 'trackProduct']),
|
||||
guides: (track.guides || []).map((guide: any) => {
|
||||
return pick(guide, ['title', 'intro', 'href', 'page.type'])
|
||||
const page = req.context.page as typeof req.context.page & {
|
||||
learningTracks?: Array<Record<string, unknown>>
|
||||
includeGuides?: Array<Record<string, unknown>>
|
||||
}
|
||||
|
||||
const learningTracks: LearningTrack[] = (page.learningTracks || []).map(
|
||||
(track: Record<string, unknown>) => ({
|
||||
title: (track.title as string) || '',
|
||||
description: (track.description as string) || '',
|
||||
trackName: (track.trackName as string) || '',
|
||||
trackProduct: (track.trackProduct as string) || '',
|
||||
guides: ((track.guides as Array<Record<string, unknown>>) || []).map(
|
||||
(guide: Record<string, unknown>) => ({
|
||||
title: (guide.title as string) || '',
|
||||
intro: (guide.intro as string) || '',
|
||||
href: (guide.href as string) || '',
|
||||
page: guide.page as { type: string } | undefined,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
}))
|
||||
)
|
||||
|
||||
return {
|
||||
...pick(page, ['title', 'intro']),
|
||||
title: page.title || '',
|
||||
intro: page.intro || '',
|
||||
learningTracks,
|
||||
includeGuides: (page.includeGuides || []).map((guide: any) => {
|
||||
includeGuides: (page.includeGuides || []).map((guide: Record<string, unknown>) => {
|
||||
return {
|
||||
...pick(guide, ['href', 'title', 'intro']),
|
||||
type: guide.type || '',
|
||||
topics: guide.topics || [],
|
||||
href: (guide.href as string) || '',
|
||||
title: (guide.title as string) || '',
|
||||
intro: (guide.intro as string) || '',
|
||||
type: (guide.type as string) || '',
|
||||
topics: (guide.topics as Array<string>) || [],
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user