From 3b6d178ef753c38b488ed8111d9d8d8662667116 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 24 Jan 2026 20:22:42 -0800 Subject: [PATCH] fix(evolution): add proper TypeScript types for API clients Co-Authored-By: Claude Opus 4.5 --- .../infrastructure/clients/conversation.client.ts | 14 +++++++++++--- .../src/infrastructure/clients/knowledge.client.ts | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/services/evolution-service/src/infrastructure/clients/conversation.client.ts b/packages/services/evolution-service/src/infrastructure/clients/conversation.client.ts index 42ab1fd..4a70250 100644 --- a/packages/services/evolution-service/src/infrastructure/clients/conversation.client.ts +++ b/packages/services/evolution-service/src/infrastructure/clients/conversation.client.ts @@ -29,6 +29,14 @@ export interface MessageDto { createdAt: Date; } +/** + * API 响应类型 + */ +interface ApiResponse { + success: boolean; + data: T; +} + /** * Conversation Service 客户端 * 用于调用 conversation-service 的内部 API @@ -64,7 +72,7 @@ export class ConversationClient { try { const response = await fetch(url); - const data = await response.json(); + const data = (await response.json()) as ApiResponse; if (!data.success) { throw new Error('Failed to fetch conversations'); @@ -85,7 +93,7 @@ export class ConversationClient { try { const response = await fetch(url); - const data = await response.json(); + const data = (await response.json()) as ApiResponse; if (!data.success) { throw new Error('Failed to fetch messages'); @@ -114,7 +122,7 @@ export class ConversationClient { try { const response = await fetch(url); - const data = await response.json(); + const data = (await response.json()) as ApiResponse<{ count: number }>; if (!data.success) { throw new Error('Failed to count conversations'); diff --git a/packages/services/evolution-service/src/infrastructure/clients/knowledge.client.ts b/packages/services/evolution-service/src/infrastructure/clients/knowledge.client.ts index 6f76210..e5ba643 100644 --- a/packages/services/evolution-service/src/infrastructure/clients/knowledge.client.ts +++ b/packages/services/evolution-service/src/infrastructure/clients/knowledge.client.ts @@ -30,6 +30,14 @@ export interface ExperienceStatisticsDto { byType: Record; } +/** + * API 响应类型 + */ +interface ApiResponse { + success: boolean; + data: T; +} + /** * Knowledge Service 客户端 * 用于调用 knowledge-service 的内部 API @@ -66,7 +74,7 @@ export class KnowledgeClient { }, body: JSON.stringify(params), }); - const data = await response.json(); + const data = (await response.json()) as ApiResponse; if (!data.success) { throw new Error('Failed to save experience'); @@ -87,7 +95,7 @@ export class KnowledgeClient { try { const response = await fetch(url); - const data = await response.json(); + const data = (await response.json()) as ApiResponse; if (!data.success) { throw new Error('Failed to get statistics'); @@ -118,7 +126,7 @@ export class KnowledgeClient { try { const response = await fetch(url); - const data = await response.json(); + const data = (await response.json()) as ApiResponse<{ count: number }>; if (!data.success) { throw new Error('Failed to count experiences');