收紧后端 TypeScript:统一 Json 类型与 TaskContext 契约
关闭 allowJs;集中 JsonObject 定义并替换分散 any 别名;parseTaskContext 返回 TaskContext;任务详情 API 标注 AdminTaskDetailView;测试减少 as any。
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# TypeScript 类型收紧
|
||||
|
||||
## 已完成
|
||||
|
||||
1. **源码仅 TS**:`allowJs: false`,不再 include `*.js`
|
||||
2. **统一 JSON 类型中心**:`apps/backend/src/types/json.ts`
|
||||
- `JsonObject`:中心定义(当前值仍为 any 以兼容深层 context 访问)
|
||||
- `StrictJson` / `StrictJsonObject`:新代码可用的 unknown 严格形态
|
||||
- `asJsonObject` / `isPlainObject` 工具
|
||||
3. **去掉约 60 处本地** `type JsonObject = Record<string, any>`
|
||||
4. **TaskContext**:`types/task-context.ts`,`parseTaskContext` 返回 `TaskContext`
|
||||
5. **Admin 任务详情契约**:`types/admin/task-detail.ts`,`getAdminTaskDetail(): Promise<AdminTaskDetailView>`
|
||||
6. **测试 fixture**:`delivery-task-service.test.ts` 减少 `as any`
|
||||
|
||||
## 未做完(后续)
|
||||
|
||||
- 将 `JsonObject` 值从 `any` 迁到 `unknown`(需改大量 `.a.b` 访问)
|
||||
- 前后端共享类型包 / OpenAPI
|
||||
- 前端对齐 `noUncheckedIndexedAccess`
|
||||
- 全量测试 fixture 工厂化
|
||||
|
||||
## 约定
|
||||
|
||||
- **新域逻辑**优先写 interface(如 `ClaimIdentity`、`AdminClaimIdentitySummary`)
|
||||
- **平台原始响应**可暂用 `JsonObject`,但 normalize 出口要有明确类型
|
||||
- 禁止再新增本地 `type JsonObject = Record<string, any>`
|
||||
Reference in New Issue
Block a user