-
Notifications
You must be signed in to change notification settings - Fork 326
Open
Description
Description
When using getAgentByName() to get an Agent stub, calling RPC methods returns type never instead of the actual return type. Accessing properties on the result causes TypeScript errors.
Reproduction
import { Agent, getAgentByName } from 'agents'
interface MyState {
count: number
}
class MyAgent extends Agent<Env, MyState> {
async myMethod(): Promise<{ data: string }> {
return { data: 'hello' }
}
}
// In worker:
const agent = await getAgentByName(env.MY_AGENT, 'id')
const result = await agent.myMethod() // result: never
console.log(result.data) // ❌ Property 'data' does not exist on type 'never'Expected behavior
result should be typed as { data: string }
Workaround
Passing the result directly to c.json({ data: result }) works because it doesn't access properties. But any property access fails.
Environment
agents: 0.3.3@cloudflare/workers-types: ^4.20251231.0wrangler: ^4.54.0
Root cause hypothesis
The Rpc.DurableObjectBranded type brand isn't properly flowing through the type inheritance chain from DurableObject → Server → Agent → user's class, causing DurableObjectStub<T> to resolve methods as returning never.
Metadata
Metadata
Assignees
Labels
No labels