Skip to content

[TypeScript SDK] Replace as any type suppressions across core SDK files #232

@santoshkumarradha

Description

@santoshkumarradha

Summary

The TypeScript SDK has 28 as any type suppressions across 4 core source files. These bypass TypeScript's type system, hide potential bugs, and make refactoring unsafe.

Current State

Agent.ts — 20 instances (worst offender)

camelCase ↔ snake_case execution context mapping (L814-839):

executionId: (ctx as any).executionId ?? ctx.execution_id ?? ctx.executionId,
runId: ctx.runId ?? (ctx as any).run_id,
workflowId: ctx.workflowId ?? (ctx as any).workflow_id,
parentExecutionId: ctx.parentExecutionId ?? (ctx as any).parent_execution_id,
sessionId: ctx.sessionId ?? (ctx as any).session_id,
actorId: ctx.actorId ?? (ctx as any).actor_id,
callerDid: (ctx as any).callerDid ?? (ctx as any).caller_did,
targetDid: (ctx as any).targetDid ?? (ctx as any).target_did,
agentNodeDid: (ctx as any).agentNodeDid ?? (ctx as any).agent_node_did

Fix: Create a RawExecutionContext type that accepts both camelCase and snake_case fields, then add a normalizeExecutionContext() utility function.

Express routing (L608, 611, 740):

this.app.post('/api/v1/reasoners/*', (req, res) => this.executeReasoner(req, res, (req.params as any)[0]));
handler(req as any, res as any);

Fix: Use proper Express ParamsDictionary types or declare route parameter types.

Parsed body access (L925-929):

if ((parsed as any).input !== undefined) { return (parsed as any).input; }
if ((parsed as any).data !== undefined) { return (parsed as any).data; }

Fix: Define ParsedBody interface with optional input and data fields.

AgentFieldClient.ts — 4 instances

// L117-118: Status enrichment
(enriched as any).status = status;
(enriched as any).responseData = respData;

// L252, 259: Discovery response mapping
compact: this.mapCompactDiscovery(parsed as any)
json: this.mapDiscoveryResponse(parsed as any)

Fix: Define proper intermediate types for enriched responses and parsed discovery payloads.

RateLimiter.ts — 2 instances

// L60, 101
const err = error as any;

Fix: Use error instanceof Error narrowing or a toError() utility.

ToolCalling.ts — 2 instances

// L371, 446
const originalTool = t as any;
const orig = t as any;

Fix: These access .description and .inputSchema on Vercel AI SDK tool() return values. The AI SDK types don't expose these properties. Either use Parameters<typeof tool>[0] to type the config, or extract the config before creating the tool.

Acceptance Criteria

  • No as any types remain in Agent.ts
  • No as any types remain in AgentFieldClient.ts
  • No as any types remain in RateLimiter.ts
  • No as any types remain in ToolCalling.ts
  • TypeScript compilation passes without errors
  • All existing tests pass
  • No @ts-ignore or @ts-expect-error introduced as replacements

Files

  • sdk/typescript/src/agent/Agent.ts (20 instances)
  • sdk/typescript/src/client/AgentFieldClient.ts (4 instances)
  • sdk/typescript/src/ai/RateLimiter.ts (2 instances)
  • sdk/typescript/src/ai/ToolCalling.ts (2 instances)

Related Issues


Using AI to solve this issue? Read our AI-Assisted Contributions guide for testing requirements, prompt strategies, and common pitfalls to avoid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions