Просмотр исходного кода

docs(standards): 更新Zod 4.0 coerce泛型语法说明

- 添加5.2节专门说明Zod 4.0中coerce需要使用泛型参数
- z.coerce.date<Date>() 和 z.coerce.number<number>() 正确用法
- 更新5.4节关键要点,包含泛型语法
- 更新7.2节Decimal字段处理示例

🤖 Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 3 недель назад
Родитель
Сommit
7863f8b93c
2 измененных файлов с 21 добавлено и 11 удалено
  1. 21 7
      docs/architecture/backend-module-package-standards.md
  2. 0 4
      mini-talent/src/app.tsx

+ 21 - 7
docs/architecture/backend-module-package-standards.md

@@ -350,11 +350,11 @@ export const ChannelSchema = z.object({
     description: '状态:1-正常,0-禁用',
     example: 1
   }),
-  createTime: z.coerce.date().openapi({
+  createTime: z.coerce.date<Date>().openapi({
     description: '创建时间',
     example: '2024-01-01T00:00:00Z'
   }),
-  updateTime: z.coerce.date().openapi({
+  updateTime: z.coerce.date<Date>().openapi({
     description: '更新时间',
     example: '2024-01-01T00:00:00Z'
   })
@@ -388,7 +388,21 @@ export const CreateChannelSchema = z.object({
 export const UpdateChannelSchema = CreateChannelSchema.partial();
 ```
 
-### 5.2 类型使用说明
+### 5.2 Zod 4.0 coerce使用说明
+
+**重要**: Zod 4.0 中,`z.coerce.date()` 和 `z.coerce.number()` 需要添加泛型参数来指定类型。
+
+```typescript
+// ✅ 正确:Zod 4.0 - 使用泛型指定类型
+z.coerce.date<Date>()       // 转换为Date类型
+z.coerce.number<number>()    // 转换为number类型
+
+// ❌ 错误:不指定泛型(Zod 4.0中类型推断可能不准确)
+z.coerce.date()
+z.coerce.number()
+```
+
+### 5.3 类型使用说明
 
 **重要**: Schema只用于请求参数验证和响应定义,**不需要导出推断的TypeScript类型**。
 
@@ -406,10 +420,10 @@ export type UpdateChannelDto = z.infer<typeof UpdateChannelSchema>;
 
 **正确做法**:只导出Schema常量,不导出推断类型。
 
-### 5.3 关键要点
+### 5.4 关键要点
 
 - **使用 `.openapi()` 装饰器**: 添加描述和示例
-- **使用 `z.coerce.date()`**: 处理日期字符串自动转换
+- **使用 `z.coerce.date<Date>()` 和 `z.coerce.number<number>()`**: Zod 4.0需要添加泛型参数
 - **使用 `.nullable().optional()`**: 处理可空字段
 - **不导出推断类型**: 类型由RPC自动推断,不需要手动导出
 
@@ -471,9 +485,9 @@ const channel = await this.repository.findOne({
 })
 totalAmount!: number;
 
-// Schema验证(使用z.coerce.number()处理字符串)
+// Schema验证(使用z.coerce.number<number>()处理字符串)
 const CreateSchema = z.object({
-  totalAmount: z.coerce.number().min(0),
+  totalAmount: z.coerce.number<number>().min(0),
 });
 ```
 

+ 0 - 4
mini-talent/src/app.tsx

@@ -1,16 +1,12 @@
 import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
 // import '@/utils/headers-polyfill.js'
 import { PropsWithChildren } from 'react'
-import { useLaunch } from '@tarojs/taro'
 import { QueryClientProvider } from '@tanstack/react-query'
 import { AuthProvider, queryClient } from '@d8d/rencai-auth-ui/hooks'
 
 import './app.css'
 
 function App({ children }: PropsWithChildren<any>) {
-  useLaunch(() => {
-    console.log('App launched.')
-  })
 
   // children 是将要会渲染的页面
   return (