Skip to content

fix: eliminate 30+ any types across provider implementations #10

Closed

Description

@stackbilt-admin

CodeBeast Audit Finding — P0 CRITICAL

Severity: P0 — Critical
Category: Type Safety
Files: openai.ts, anthropic.ts, cloudflare.ts, factory.ts, index.ts, cost-tracker.ts, retry.ts

Problem

The library claims strict TypeScript ("strict": true in tsconfig) but has 30+ untyped any usages across production source files. This defeats the purpose of strict mode and creates runtime safety gaps.

Worst Offenders

Cloudflare provider (12 uses) — the most-used provider:

extractText(result: any): string       // cloudflare.ts:389
extractToolCalls(result: any): ToolCall[] // cloudflare.ts:442
unwrapResult(result: any): any         // cloudflare.ts:553

OpenAI provider (6 uses):

tool_calls?: any[];   // openai.ts:19
tools?: any[];        // openai.ts:29
tool_choice?: any;    // openai.ts:30
body: any             // openai.ts:213

Anthropic provider (6 uses):

input?: any;          // anthropic.ts:22,48
tools?: any[];        // anthropic.ts:35
tool_choice?: any;    // anthropic.ts:36

Public API surface:

getCostAnalytics(): any  // factory.ts:422, index.ts:245

Impact

  • One malformed Workers AI response → undefined is not a function at runtime
  • Consumers of getCostAnalytics() get zero type information from a cost tracking library
  • Tool call interfaces are untyped despite ToolCall type existing in types.ts
  • Reduces confidence in the library's correctness guarantees

Fix

  1. Replace any in tool call interfaces with ToolCall[] from types.ts
  2. Type Cloudflare result parameters against Workers AI response shapes
  3. Type getCostAnalytics() return with a proper interface
  4. Add // eslint-disable-next-line @typescript-eslint/no-explicit-any only where truly unavoidable (external API boundaries)

🤖 Filed by CodeBeast audit

Activity

  1. added
    bug
    P0-critical
    audit
    type-safety
    on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0-criticalauditbugtype-safety

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions