Skip to content

fix: 消除 8 个 as any — MCP 通知、结构化输出、流事件的类型安全修复 - #1

Merged
James-FE merged 1 commit into
mainfrom
fix/eliminate-as-any
Jun 7, 2026
Merged

fix: 消除 8 个 as any — MCP 通知、结构化输出、流事件的类型安全修复#1
James-FE merged 1 commit into
mainfrom
fix/eliminate-as-any

Conversation

@James-FE

@James-FE James-FE commented Jun 7, 2026

Copy link
Copy Markdown
Owner

背景

在 CCP (CC_Pure) 项目上跑 bunx tsc --noEmit 时发现 94 处 as any 类型断言。经与上游 CCB 源码交叉验证,其中 8 处在上游同样存在 — 即 Anthropic 自己的闭源 CLI 代码里也是 as any。

修复内容

A 组:MCP 通知 Schema 工厂 (4 处)

  • lazySchema<T>() 返回的 schema 常量加 : () => AnyObjectSchema 类型标注
  • 文件: useIdeSelection.ts, useIdeLogging.ts, usePromptsFromClaudeInChrome.tsx, channelNotification.ts + cli.tsx

B 组:结构化输出附件 (2 处)

  • 新增 isStructuredOutputAttachmentMessage() type guard
  • 文件: execAgentHook.ts

C 组:子代理流事件 (3 处)

  • 新增 isMessageDeltaStreamEvent() type guard
  • 文件: forkedAgent.ts

验证

  • 目标文件 as any 数量:8 → 0
  • 不改变任何运行时行为
  • 类型标注告知 TS 已知事实,非欺骗编译器

…m events

- Group A: Add : () => AnyObjectSchema type annotations to MCP notification
  schema constants (useIdeSelection, useIdeLogging, usePrompts, channelNotification)
- Group B: Add isStructuredOutputAttachmentMessage type guard for structured
  output attachment payloads (execAgentHook)
- Group C: Add isMessageDeltaStreamEvent type guard for message_delta
  stream event usage extraction (forkedAgent)

These as any casts also exist in the upstream CCB source — this fix provides
real type safety without changing any runtime behavior.
@James-FE
James-FE merged commit faa03d3 into main Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant