claude-agent-sdk: SDKMessage type resolves to any due to missing type declarations
Status Fixed / completed
Maintainer reply None cached
Activity 3 comments · opened Feb 23, 2026 · closed Feb 27, 2026
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
3 Comments
Same here.
I learned that this was supposed to be in a different repository
Filled bug there and its being worked on:
https://github.com/anthropics/claude-agent-sdk-typescript/issues/206#issuecomment-3968985269
Closing here.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.