Skip to content

Commit 66ffb9c

Browse files
committed
chore: add type checking in frontend
1 parent 30506c6 commit 66ffb9c

8 files changed

Lines changed: 78 additions & 15 deletions

File tree

frontend/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"lint": "eslint ./src",
1616
"lint:fix": "eslint ./src --fix",
1717
"preview": "vite preview",
18-
"start": "npm run dev"
18+
"start": "npm run dev",
19+
"typecheck": "vue-tsc --noEmit --skipLibCheck"
1920
},
2021
"dependencies": {
2122
"@noble/ciphers": "^2.1.1",
@@ -56,7 +57,8 @@
5657
"eslint": "^9.39.2",
5758
"rollup-plugin-visualizer": "^6.0.5",
5859
"typescript": "^5.9.3",
59-
"vite": "7.3.1"
60+
"vite": "7.3.1",
61+
"vue-tsc": "^3.2.5"
6062
},
6163
"browserslist": [
6264
"> 0.3%",

frontend/src/api/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { WebsiteInformation } from '@backend/controllers/utils'
21
import type { CourseRole } from '@backend/types'
32
import type { CourseEntityEditable, CourseEntityItem, CourseEntityPreview, CourseEntityViewWithRole, CourseMemberView, ProblemEntityItem, SolutionEntity, TagEntity, TagEntityForm, TagEntityItem, TagEntityPreview, TagEntityView } from '@backend/types/entity'
43
import type { Enveloped, Paginated } from '@putongoj/shared'
@@ -9,7 +8,7 @@ import { instance } from './instance'
98
export * from './instance'
109

1110
const utils = {
12-
getWebsiteInformaton: () => instance.get<WebsiteInformation>('/website'),
11+
getWebsiteInformaton: () => instance.get('/website'),
1312
getTime: () => instance.get<TimeResp>('/servertime'),
1413
getRanklist: (params: { [key: string]: any }) =>
1514
instance.get('/ranklist/list', { params }),

frontend/src/api/instance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Enveloped } from '@putongoj/shared'
22
import type { AxiosRequestConfig, AxiosResponse } from 'axios'
3-
import { ErrorCode } from '@putongoj/shared'
43
import axios from 'axios'
54

65
// 设置全局axios默认值
@@ -44,7 +43,7 @@ async function handleRequest<T> (request: Promise<AxiosResponse<Enveloped<T>>>):
4443
} else {
4544
return {
4645
success: false,
47-
code: ErrorCode.NetworkError,
46+
code: -1,
4847
message: err.message || 'Network error',
4948
data: null,
5049
requestId: 'N/A',

frontend/src/store/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import type { WebsiteInformation } from '@backend/controllers/utils'
1+
import type { OAuthProvider } from '@putongoj/shared/dist/consts'
22
import { defineStore } from 'pinia'
33
import vditorInfo from 'vditor/package.json'
44
import api from '@/api'
55
import { privilege } from '@/utils/constant'
66
import { setServerPublicKey } from '@/utils/crypto'
77

8+
interface WebsiteInformation {
9+
title: string
10+
buildSHA: string
11+
buildTime: number
12+
apiPublicKey: string
13+
oauthEnabled: Record<OAuthProvider, boolean>
14+
helpDocURL?: string
15+
}
16+
817
export const useRootStore = defineStore('root', {
918
state: () => ({
1019
currentTime: Date.now(),

frontend/src/types/api.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Paginated, ProblemBrief, RanklistInfo, RawRanklist } from '.'
1+
import type { Paginated, ProblemBrief } from '.'
22

33
export interface PaginateParams {
44
page: number
@@ -15,8 +15,3 @@ export interface FindProblemsResponse {
1515
list: Paginated<ProblemBrief>
1616
solved: number[]
1717
}
18-
19-
export interface RanklistResponse {
20-
ranklist: RawRanklist
21-
info: RanklistInfo
22-
}

frontend/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"useDefineForClassFields": true,
99
"baseUrl": ".",
1010
"module": "esnext",
11-
"moduleResolution": "node",
11+
"moduleResolution": "bundler",
1212
"paths": {
1313
"@/*": [
1414
"src/*"

pnpm-lock.yaml

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared/src/types/api/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type SuccessEnveloped<T = any> = {
4141

4242
export type ErrorEnveloped = {
4343
success: false
44-
code: ErrorCode
44+
code: ErrorCode | -1
4545
message: string
4646
data: null
4747
requestId: string

0 commit comments

Comments
 (0)