Skip to content

Commit b69590a

Browse files
committed
fixing typing errors
1 parent 33210cb commit b69590a

File tree

11 files changed

+218
-196
lines changed

11 files changed

+218
-196
lines changed

apps/nextjs/app/[lang]/[pathPrefix]/[pathSuffix]/__tests__/page.test.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '@testing-library/jest-dom'
55
import Page from '../page.tsx'
66
import React, { Suspense } from 'react'
77

8-
(global as any).IS_REACT_ACT_ENVIRONMENT = true;
8+
(global as unknown).IS_REACT_ACT_ENVIRONMENT = true;
99

1010
// Mock next/navigation
1111
vi.mock('next/navigation', () => ({
@@ -19,12 +19,12 @@ vi.mock('next/navigation', () => ({
1919
}))
2020

2121
// Mock axios
22-
interface AxiosGetReturn { data: any }
22+
interface AxiosGetReturn { data: unknown }
2323
const axiosGet = vi.fn(
24-
(..._args: any[]): Promise<AxiosGetReturn> => Promise.resolve({ data: [] }),
24+
(): Promise<AxiosGetReturn> => Promise.resolve({ data: [] }),
2525
)
2626
vi.mock('axios', () => ({
27-
default: { get: (...args: any[]) => axiosGet(...args) },
27+
default: { get: (...args: ReadonlyArray<string>) => axiosGet(...args) },
2828
}))
2929

3030
// Mock next-auth/react
@@ -83,7 +83,7 @@ vi.mock('@/components/GoodDollarClaimButton', () => ({
8383

8484
// Mock window.fillInTheBlank
8585
if (typeof global.window !== 'undefined') {
86-
(global.window as any).fillInTheBlank = []
86+
(global.window as unknown as { fillInTheBlank: unknown[] }).fillInTheBlank = []
8787
}
8888

8989
// Mock localStorage
@@ -135,7 +135,7 @@ describe('Guide Page Component', () => {
135135
})
136136
useAccountMock.mockReturnValue({ address: '0x123', isConnected: true })
137137
axiosGet.mockReset()
138-
// @ts-ignore
138+
// @ts-expect-error
139139
global.window.alert = vi.fn()
140140
process.env.NEXT_PUBLIC_API_BUSCA_CURSOS_URL = API_BUSCA_URL
141141
process.env.NEXT_PUBLIC_API_PRESENTA_CURSO_URL = API_PRESENTA_URL
@@ -290,4 +290,3 @@ describe('Guide Page Component', () => {
290290
})
291291
})
292292
})
293-

apps/nextjs/app/[lang]/[pathPrefix]/[pathSuffix]/page.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import axios from 'axios'
3+
import axios, { AxiosError } from 'axios'
44
import { useSession } from 'next-auth/react'
55
import Link from 'next/link'
66
import { use, useEffect, useState, useCallback } from 'react'
@@ -51,15 +51,14 @@ export default function Page({ params }: PageProps) {
5151
const [creditsHtml, setCreditsHtml] = useState('')
5252
const [isClient, setIsClient] = useState(false)
5353

54-
const htmlDeMd = useCallback((md: string | undefined) => {
54+
const htmlDeMd = useCallback((md: string) => {
5555
if (!md) return ''
56-
const processor = unified()
56+
const processor = (unified() as any)
5757
.use(remarkParse)
5858
.use(remarkGfm)
5959
.use(remarkDirective)
6060
.use(remarkFrontmatter)
6161
.use(remarkFillInTheBlank, { url: `${pathSuffix}/test` })
62-
// @ts-ignore
6362
.use(remarkRehype, { allowDangerousHtml: true })
6463
.use(rehypeStringify, { allowDangerousHtml: true })
6564
const html = processor.processSync(md).toString()
@@ -68,7 +67,7 @@ export default function Page({ params }: PageProps) {
6867
localStorage.setItem(
6968
'fillInTheBlank',
7069
JSON.stringify(
71-
(window as Window & { fillInTheBlank?: any[] }).fillInTheBlank || [],
70+
(window as Window & { fillInTheBlank?: [] }).fillInTheBlank || [],
7271
),
7372
)
7473
}
@@ -97,7 +96,7 @@ export default function Page({ params }: PageProps) {
9796
'gyroscope; picture-in-picture; web-share" ' +
9897
'referrerpolicy="strict-origin-when-cross-origin" ' +
9998
'allowfullscreen></iframe>' +
100-
'</p>',
99+
'</p',
101100
)
102101
.replaceAll('<li><p>([^<]*)</p></li>', '<li>$1</li>')
103102
.replaceAll('<p>', '<p class="pt-2 pb-2">')
@@ -111,20 +110,22 @@ export default function Page({ params }: PageProps) {
111110
if (course && guideNumber > 0) {
112111
const fetchGuideContent = async () => {
113112
try {
114-
let nurl = `${process.env.NEXT_PUBLIC_AUTH_URL}/api/guide?courseId=${course.id}` +
113+
const nurl = `${process.env.NEXT_PUBLIC_AUTH_URL}/api/guide?courseId=${course.id}` +
115114
`&lang=${lang}&prefix=${pathPrefix}&guide=${pathSuffix}&guideNumber=${guideNumber}`
116115

117-
const response = await axios.get(nurl)
116+
const response = await axios.get<{ markdown?: string, message?: string }>(nurl)
118117
if (response.data && response.data.markdown) {
119118
setGuideHtml(htmlDeMd(response.data.markdown))
120119
} else if (response.data && response.data.message) {
121120
throw new Error(response.data.message)
122121
}
123-
setCreditsHtml(htmlDeMd(course.creditosMd))
122+
setCreditsHtml(htmlDeMd(course.creditosMd || ''))
124123

125-
} catch (err: any) {
126-
console.error("Error fetching guide content:", err)
127-
setGuideHtml(`<p>Error: ${err.message}</p>`)
124+
} catch (err) {
125+
if (err instanceof AxiosError) {
126+
console.error("Error fetching guide content:", err)
127+
setGuideHtml(`<p>Error: ${err.message}</p>`)
128+
}
128129
}
129130
}
130131
fetchGuideContent()
@@ -250,5 +251,3 @@ export default function Page({ params }: PageProps) {
250251
<div>&nbsp;</div>
251252
</>)
252253
}
253-
254-

apps/nextjs/app/[lang]/[pathPrefix]/[pathSuffix]/test/page.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import axios from 'axios'
3+
import axios, { AxiosError } from 'axios'
44
import { getCsrfToken, useSession } from 'next-auth/react'
55
import { use, useEffect, useState } from 'react'
66
import { useAccount, useConfig, useWriteContract } from 'wagmi'
@@ -39,18 +39,17 @@ export default function Page({
3939
}) {
4040
const { address } = useAccount()
4141
const { data: session } = useSession()
42-
const { data: hash, writeContract } = useWriteContract()
42+
const { data: hash } = useWriteContract()
4343
const wagmiConfig = useConfig()
4444
const parameters = use(params)
4545
const { lang, pathPrefix, pathSuffix } = parameters
4646

47-
const {
48-
course,
49-
loading,
50-
error,
51-
myGuide,
52-
guideNumber,
53-
coursePath,
47+
const {
48+
course,
49+
loading,
50+
error,
51+
myGuide,
52+
guideNumber
5453
} = useGuideData({ lang, pathPrefix, pathSuffix })
5554

5655
const [thisGuidePath, setThisGuidePath] = useState('')
@@ -83,11 +82,10 @@ export default function Page({
8382
console.log('Transaction receipt', receipt)
8483
// Actualizar el estado de la guía localmente para reflejar el pago
8584
if (myGuide) {
86-
// @ts-ignore
8785
myGuide.receivedScholarship = true
8886
}
8987
setFlashWarning('')
90-
}).catch((e) => {
88+
}).catch((e: Error) => {
9189
console.error(e)
9290
setFlashError(e.message)
9391
setFlashWarning('')
@@ -103,7 +101,7 @@ export default function Page({
103101
if (!csrfToken) throw new Error('Could not get CSRF token')
104102
setGCsrfToken(csrfToken)
105103

106-
let urlc =
104+
const urlc =
107105
`/api/crossword?courseId=${course.id}` +
108106
`&lang=${lang}` +
109107
`&prefix=${pathPrefix}` +
@@ -113,17 +111,19 @@ export default function Page({
113111
`&token=${csrfToken}`
114112

115113
console.log(`Fetching Crossword: ${urlc}`)
116-
const response = await axios.get(urlc)
114+
const response = await axios.get<{grid: Cell[][], placements: WordPlacement[], message?: string}>(urlc)
117115

118116
if (response.data.message) {
119117
throw new Error(response.data.message)
120118
}
121119
setGrid(response.data.grid)
122120
setPlacements(response.data.placements)
123121
setThisGuidePath(`/${lang}/${pathPrefix}/${pathSuffix}`)
124-
} catch (err: any) {
125-
console.error(err)
126-
setFlashError(err.message)
122+
} catch (err) {
123+
if (err instanceof AxiosError) {
124+
console.error(err)
125+
setFlashError(err.message)
126+
}
127127
}
128128
}
129129
}
@@ -201,7 +201,7 @@ export default function Page({
201201
setScholarshipTx('')
202202

203203
try {
204-
const response = await axios.post('/api/check-crossword', {
204+
const response = await axios.post<{mistakesInCW: [], message: string, scholarshipResult: string}>('/api/check-crossword', {
205205
courseId: +course.id,
206206
guideId: guideNumber,
207207
lang: lang,
@@ -226,17 +226,18 @@ export default function Page({
226226
)
227227
} else {
228228
if (myGuide) {
229-
// @ts-ignore
230229
myGuide.completed = true
231230
}
232231
setFlashSuccess(response.data.message || '')
233232
if (response.data.scholarshipResult) {
234233
setScholarshipTx(response.data.scholarshipResult)
235234
}
236235
}
237-
} catch (error: any) {
238-
console.error(error)
239-
setFlashError(error.response?.data?.error || error.message)
236+
} catch (error) {
237+
if (error instanceof AxiosError) {
238+
console.error(error)
239+
setFlashError(error.response?.data?.error || error.message)
240+
}
240241
} finally {
241242
setIsSubmitting(false)
242243
}

apps/nextjs/app/[lang]/[pathPrefix]/__tests__/page.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ vi.mock('next/navigation', () => ({
1616
}))
1717

1818
// Mock axios
19-
interface AxiosGetReturn { data: any }
19+
interface AxiosGetReturn { data: unknown }
2020
const axiosGet = vi.fn(
21-
(..._args: any[]): Promise<AxiosGetReturn> => Promise.resolve({ data: [] }),
21+
(): Promise<AxiosGetReturn> => Promise.resolve({ data: [] }),
2222
)
2323
vi.mock('axios', () => ({
24-
default: { get: (...args: any[]) => axiosGet(...args) },
24+
default: { get: (...args: ReadonlyArray<string>) => axiosGet(...args) },
2525
}))
2626

2727
// Mock next-auth/react
@@ -70,7 +70,7 @@ vi.mock('unified', () => ({
7070

7171
// Mock Button component
7272
vi.mock('@/components/ui/button', () => ({
73-
Button: ({ children, ...props }: any) => (
73+
Button: ({ children, ...props }: {children: React.ReactNode}) => (
7474
<button {...props}>{children}</button>
7575
),
7676
}))
@@ -127,7 +127,7 @@ describe('Course List Page Component', () => {
127127
useAccountMock.mockReturnValue({ address: '0x123', isConnected: true })
128128
axiosGet.mockReset()
129129
// Mock alert to avoid jsdom errors
130-
// @ts-ignore
130+
// @ts-expect-error Mocking alert is necessary for jsdom environment
131131
global.window.alert = vi.fn()
132132
// Mock environment variables
133133
process.env.NEXT_PUBLIC_API_BUSCA_CURSOS_URL = API_BUSCA_URL
@@ -322,4 +322,3 @@ describe('Course List Page Component', () => {
322322
})
323323
})
324324
})
325-

apps/nextjs/app/[lang]/[pathPrefix]/page.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { use, useEffect, useState } from 'react'
44
import { useSession } from 'next-auth/react'
55
import { useAccount } from 'wagmi'
6+
import Image from 'next/image'
67

78
import { useGuideData } from '@/lib/hooks/useGuideData'
89

@@ -52,10 +53,8 @@ export default function Page({ params }: PageProps) {
5253

5354
useEffect(() => {
5455
if (course) {
55-
// @ts-ignore
56-
setHtmlSummary(htmlDeMd(course.resumenMd))
57-
// @ts-ignore
58-
setHtmlExtended(htmlDeMd(course.ampliaMd))
56+
setHtmlSummary(htmlDeMd(course.resumenMd || ''))
57+
setHtmlExtended(htmlDeMd(course.ampliaMd || ''))
5958

6059
let guias = "<ol class='list-decimal text-primary-foreground'>\n"
6160
for (const guia of course.guias) {
@@ -105,7 +104,6 @@ export default function Page({ params }: PageProps) {
105104
<h1 className="text-2xl lg:text-3xl font-bold mb-2">
106105
{course.titulo}
107106
</h1>
108-
{/* @ts-ignore */}
109107
<h2 className="text-lg lg:text-xl font-semibold text-gray-600">
110108
{course.subtitulo}
111109
</h2>
@@ -128,16 +126,16 @@ export default function Page({ params }: PageProps) {
128126
</div>
129127
</header>
130128

129+
{course.imagen && (
131130
<figure className="my-6">
132-
{/* @ts-ignore */}
133-
<img
131+
<Image
134132
src={course.imagen}
135133
width="300"
136-
alt={course.altImagen}
134+
height="200"
135+
alt={course.altImagen || 'Course image'}
137136
className="mx-auto rounded-lg shadow-md"
138137
/>
139138
<figcaption className="text-sm text-gray-500 mt-3 text-center">
140-
{/* @ts-ignore */}
141139
<a
142140
href={course.enlaceImagen}
143141
target="_blank"
@@ -147,6 +145,7 @@ export default function Page({ params }: PageProps) {
147145
</a>
148146
</figcaption>
149147
</figure>
148+
)}
150149

151150
<article
152151
className="prose max-w-prose text-justify text-gray-700"
@@ -172,4 +171,3 @@ export default function Page({ params }: PageProps) {
172171
</div>
173172
)
174173
}
175-

apps/nextjs/app/[lang]/__tests__/page.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('Main Page Component', () => {
6161
data: { writeContract: vi.fn().mockResolvedValue('0xhash') },
6262
})
6363
mockedAxios.get.mockResolvedValue({ data: [] })
64-
// @ts-ignore
64+
// @ts-expect-error
6565
global.window.alert = vi.fn()
6666
})
6767

0 commit comments

Comments
 (0)