claude-agent-sdk: SDKMessage type resolves to any due to missing type declarations
Bug
The SDKMessage type exported from @anthropic-ai/claude-agent-sdk resolves to any in TypeScript projects that use skipLibCheck: true (which is the common default).
Root Cause
In sdk.d.ts (line 1533), SDKMessage is defined as a union that includes SDKRateLimitEvent and SDKPromptSuggestionMessage:
export declare type SDKMessage = SDKAssistantMessage | SDKUserMessage | ... | SDKRateLimitEvent | SDKPromptSuggestionMessage;
However, neither SDKRateLimitEvent nor SDKPromptSuggestionMessage are declared anywhere in sdk.d.ts. This means:
- With
skipLibCheck: false→ TypeScript reportsTS2304: Cannot find name 'SDKRateLimitEvent'andTS2304: Cannot find name 'SDKPromptSuggestionMessage' - With
skipLibCheck: true(default in most projects) → TypeScript silently degrades the entireSDKMessageunion toany
This cascades through Query (which extends AsyncGenerator<SDKMessage, void>), so any for await (const message of messages) loop has message typed as any, losing all type safety.
Reproduction
import { query, type SDKMessage } from '@anthropic-ai/claude-agent-sdk'
// This should error but doesn't — SDKMessage is any
const check: number = {} as SDKMessage
async function test() {
const messages = query({ prompt: 'hi', options: { model: 'sonnet' } })
for await (const message of messages) {
// message is any — no autocomplete, no type narrowing
message.nonExistentProperty // no error
}
}
Additional broken declarations
Running tsc --skipLibCheck false also reveals:
- Missing
@modelcontextprotocol/sdk/types.jsand@modelcontextprotocol/sdk/server/mcp.jsimports (lines 4-6, 9) SDKStreamlinedTextMessageandSDKStreamlinedToolUseSummaryMessagenot exported fromcoreTypes(line 1895)
Expected Fix
Add the missing type declarations for SDKRateLimitEvent and SDKPromptSuggestionMessage to sdk.d.ts.
Environment
@anthropic-ai/claude-agent-sdk: installed via Claude Code- TypeScript with
skipLibCheck: true,moduleResolution: "bundler" - Runtime: Bun
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗