[P2] API接口参数建议使用具体类型替代any #3

Open
opened 2026-01-13 16:07:09 +08:00 by tangweijie · 1 comment
Owner

问题描述

API 接口定义中使用了 any 类型,失去了 TypeScript 的类型安全优势。

代码位置: frontend/src/api/prison/question/index.ts:31

getQuestionPage: async (params: any) => {  // params 应该是具体类型
  return await request.get({ url: `/prison/question/page`, params })
},

// 以及 URL 构建使用字符串拼接
getQuestion: async (id: number) => {
  return await request.get({ url: `/prison/question/get?id=` + id })  // 建议改用 params
},

影响

  • IDE 无法提供自动补全
  • 编译时无法检测参数错误
  • 容易引入拼写错误等低级 bug

建议修复

// 定义查询参数类型
interface QuestionPageParams {
  pageNo: number
  pageSize: number
  questionnaireId?: number
  title?: string
  type?: number
  status?: number
}

// API 接口使用具体类型
getQuestionPage: async (params: QuestionPageParams) => {
  return await request.get({ url: `/prison/question/page`, params })
},

// 使用 params 对象构建 URL(推荐方式)
getQuestion: async (id: number) => {
  return await request.get({ url: `/prison/question/get`, params: { id } })
},

优先级

P2 - 低(代码规范)

标签

enhancement frontend typescript

## 问题描述 API 接口定义中使用了 `any` 类型,失去了 TypeScript 的类型安全优势。 **代码位置**: `frontend/src/api/prison/question/index.ts:31` ```typescript getQuestionPage: async (params: any) => { // params 应该是具体类型 return await request.get({ url: `/prison/question/page`, params }) }, // 以及 URL 构建使用字符串拼接 getQuestion: async (id: number) => { return await request.get({ url: `/prison/question/get?id=` + id }) // 建议改用 params }, ``` ## 影响 - IDE 无法提供自动补全 - 编译时无法检测参数错误 - 容易引入拼写错误等低级 bug ## 建议修复 ```typescript // 定义查询参数类型 interface QuestionPageParams { pageNo: number pageSize: number questionnaireId?: number title?: string type?: number status?: number } // API 接口使用具体类型 getQuestionPage: async (params: QuestionPageParams) => { return await request.get({ url: `/prison/question/page`, params }) }, // 使用 params 对象构建 URL(推荐方式) getQuestion: async (id: number) => { return await request.get({ url: `/prison/question/get`, params: { id } }) }, ``` ## 优先级 P2 - 低(代码规范) ## 标签 enhancement frontend typescript
Author
Owner

状态更新

优先级: P2 - 低(代码规范)

当前状态: 尚未修复

建议在后续迭代中处理。


此 Issue 由代码审查生成,记录在 Gitea 以便跟踪。

## 状态更新 **优先级**: P2 - 低(代码规范) **当前状态**: 尚未修复 建议在后续迭代中处理。 --- *此 Issue 由代码审查生成,记录在 Gitea 以便跟踪。*
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tangweijie/xlcp-frontend#3
No description provided.